Dataset Viewer
Auto-converted to Parquet Duplicate
c
stringlengths
487
1.78k
s
stringlengths
1.48k
5.23k
#include <stdio.h> #include <stdlib.h> struct object { int val; int index; }; static int compare(const void *a, const void *b) { return ((struct object *) a)->val - ((struct object *) b)->val; } int * twosum(int *nums, int numsSize, int target, int *returnSize) { int i, j; struct object *objs =...
.text compare: pushq %rbp movq %rsp, %rbp movq %rdi, -8(%rbp) movq %rsi, -16(%rbp) movq -8(%rbp), %rax movl (%rax), %edx movq -16(%rbp), %rax movl (%rax), %eax subl %eax, %edx movl %edx, %eax popq %rbp ret .globl twosum twosum: pushq %rbp movq %rsp, %rbp subq $64, %rsp movq %rdi, -40(%rbp) movl %esi,...
#include <stdio.h> #include <stdbool.h> bool isPalindrome(int x) { if (x < 0) return false; int t = x; int mask = 1; while (t >= 10) { mask *= 10; t /= 10; } int l, r; while (x) { r = x % 10; l = x / mask; if (l != r) return false; x = (x % ...
.text .globl isPalindrome isPalindrome: pushq %rbp movq %rsp, %rbp movl %edi, -20(%rbp) cmpl $0, -20(%rbp) jns .L2 movl $0, %eax jmp .L3 .L2: movl -20(%rbp), %eax movl %eax, -4(%rbp) movl $1, -8(%rbp) jmp .L4 .L5: movl -8(%rbp), %edx movl %edx, %eax sall $2, %eax addl %edx, %eax addl %eax, %eax movl ...
#include <stdio.h> #include <stdbool.h> bool isValidSudoku(char** board, int boardSize, int* boardColSize) { bool rows[9][9] = {false}; bool cols[9][9] = {false}; bool boxes[9][9] = {false}; for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { if (board[i][j] != '.') { ...
.text .globl isValidSudoku isValidSudoku: pushq %rbp movq %rsp, %rbp subq $216, %rsp movq %rdi, -312(%rbp) movl %esi, -316(%rbp) movq %rdx, -328(%rbp) leaq -112(%rbp), %rdx movl $0, %eax movl $10, %ecx movq %rdx, %rdi rep stosq movq %rdi, %rdx movb %al, (%rdx) addq $1, %rdx leaq -208(%rbp), %rdx movl ...
#include <stdio.h> #include <stdlib.h> #include <string.h> char* toLowerCase(char* s) { for(int i=0; i<strlen(s); i++) { if(s[i] >= 65 && s[i] <= 90) { s[i] += 32; } } return s; } int main() { char str0[] = "Hello"; char str1[] = "here"; char str2[] = "LOVELY"; ...
.text .globl toLowerCase toLowerCase: pushq %rbp movq %rsp, %rbp pushq %rbx subq $40, %rsp movq %rdi, -40(%rbp) movl $0, -20(%rbp) jmp .L2 .L4: movl -20(%rbp), %eax movslq %eax, %rdx movq -40(%rbp), %rax addq %rdx, %rax movzbl (%rax), %eax cmpb $64, %al jle .L3 movl -20(%rbp), %eax movslq %eax, %rdx ...
#include <stdio.h> #include <stdbool.h> #include <string.h> #include <stdlib.h> bool isValid(char * s) { char stack[strlen(s)]; int top = -1; for (int i = 0; s[i] != '\0'; i++) { if (s[i] == '(' || s[i] == '{' || s[i] == '[') { stack[++top] = s[i]; // Push opening bracket }...
.text .globl isValid isValid: pushq %rbp movq %rsp, %rbp pushq %r15 pushq %r14 pushq %r13 pushq %r12 pushq %rbx subq $56, %rsp movq %rdi, -88(%rbp) movq %rsp, %rax movq %rax, %rbx movq -88(%rbp), %rax movq %rax, %rdi call strlen@PLT movq %rax, %rdx subq $1, %rdx movq %rdx, -64(%rbp) movq %rax, %r14 ...
#include <stdio.h> #include <stdlib.h> #include <string.h> int calPoints(char** operations, int operationsSize) { int *record = (int *) malloc(sizeof(int)*operationsSize); int s = 0, index = 0; for (int i = 0; i < operationsSize; i++) { if (strcmp(operations[i],"C") == 0) { record[index...
.text .section .rodata .LC0: .string "C" .LC1: .string "D" .LC2: .string "+" .text .globl calPoints calPoints: pushq %rbp movq %rsp, %rbp pushq %rbx subq $56, %rsp movq %rdi, -56(%rbp) movl %esi, -60(%rbp) movl -60(%rbp), %eax cltq salq $2, %rax movq %rax, %rdi call malloc@PLT movq %rax, -40(%rbp) m...
#include <stdbool.h> #include <string.h> #include <stdio.h> bool isAnagram(char * s, char * t){ int len_s = strlen(s); int len_t = strlen(t); if (len_s != len_t) return false; int counts[26] = {0}; for (int i = 0; i < len_s; i++) { counts[s[i] - 'a']++; counts[t[i] - 'a']--; } ...
.text .globl isAnagram isAnagram: pushq %rbp movq %rsp, %rbp subq $144, %rsp movq %rdi, -136(%rbp) movq %rsi, -144(%rbp) movq -136(%rbp), %rax movq %rax, %rdi call strlen@PLT movl %eax, -12(%rbp) movq -144(%rbp), %rax movq %rax, %rdi call strlen@PLT movl %eax, -16(%rbp) movl -12(%rbp), %eax cmpl -16(%r...
#include <stdio.h> #include <stdbool.h> bool threeConsecutiveOdds(int* arr, int arrSize) { for (int i = 0; i < arrSize - 2; i++) { if (arr[i] % 2 != 0 && arr[i + 1] % 2 != 0 && arr[i + 2] % 2 != 0) { return true; } } return false; } int main() { int arr1[] = {2, 6, 4, 1}; ...
.text .globl threeConsecutiveOdds threeConsecutiveOdds: pushq %rbp movq %rsp, %rbp movq %rdi, -24(%rbp) movl %esi, -28(%rbp) movl $0, -4(%rbp) jmp .L2 .L5: movl -4(%rbp), %eax cltq leaq 0(,%rax,4), %rdx movq -24(%rbp), %rax addq %rdx, %rax movl (%rax), %eax andl $1, %eax testl %eax, %eax je .L3 movl -...
#include <stdio.h> void merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n){ int i = m - 1; int j = n -1; while (i>=0 && j>=0) { if(nums1[i] > nums2[j]) { nums1[i + j + 1] = nums1[i]; i--; } else { nums1[i + j + 1] = nums2[j]; ...
.text .globl merge merge: pushq %rbp movq %rsp, %rbp movq %rdi, -24(%rbp) movl %esi, -28(%rbp) movl %edx, -32(%rbp) movq %rcx, -40(%rbp) movl %r8d, -44(%rbp) movl %r9d, -48(%rbp) movl -32(%rbp), %eax subl $1, %eax movl %eax, -4(%rbp) movl -48(%rbp), %eax subl $1, %eax movl %eax, -8(%rbp) jmp .L2 .L5: ...
#include <stdio.h> #include <stdlib.h> int addDigits(int num) { if(num == 0) return 0; if(num < 10) return num; int rem; int sum = 0; while(num >= 10) { while(num > 0) { rem = num % 10; sum += rem; num /= 10; } num = sum; sum = 0;...
.text .globl addDigits addDigits: pushq %rbp movq %rsp, %rbp movl %edi, -20(%rbp) cmpl $0, -20(%rbp) jne .L2 movl $0, %eax jmp .L3 .L2: cmpl $9, -20(%rbp) jg .L4 movl -20(%rbp), %eax jmp .L3 .L4: movl $0, -4(%rbp) jmp .L5 .L7: movl -20(%rbp), %edx movslq %edx, %rax imulq $1717986919, %rax, %rax shrq ...
#include <stdio.h> int sumOfMultiples(int n) { int sum = 0; for (int i = 1; i <= n; i++) { if (i % 3 == 0 || i % 5 == 0 || i % 7 == 0) { sum += i; } } return sum; } int main() { int n0 = 7; int n1 = 10; int n2 = 9; if (sumOfMultiples(n0) == 21 && sumOfMulti...
.text .globl sumOfMultiples sumOfMultiples: pushq %rbp movq %rsp, %rbp movl %edi, -20(%rbp) movl $0, -4(%rbp) movl $1, -8(%rbp) jmp .L2 .L5: movl -8(%rbp), %ecx movslq %ecx, %rax imulq $1431655766, %rax, %rax shrq $32, %rax movq %rax, %rdx movl %ecx, %eax sarl $31, %eax subl %eax, %edx movl %edx, %eax ...
#include <stdbool.h> #include <string.h> #include <stdio.h> bool canConstruct(char* r, char* m) { int arr[26] = {}; for(; *m; ){ int idx = *(m) - 'a'; arr[idx]++; *(m)++; } for(; *r; ){ int idx = *(r) - 'a'; arr[idx]--; if(arr[idx] == -1) retu...
.text .globl canConstruct canConstruct: pushq %rbp movq %rsp, %rbp subq $8, %rsp movq %rdi, -120(%rbp) movq %rsi, -128(%rbp) leaq -112(%rbp), %rdx movl $0, %eax movl $13, %ecx movq %rdx, %rdi rep stosq jmp .L2 .L3: movq -128(%rbp), %rax movzbl (%rax), %eax movsbl %al, %eax subl $97, %eax movl %eax, -8...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> int compar (const void * elem1, const void * elem2) { int f = *((int*)elem1); int s = *((int*)elem2); if (f > s) return 1; if (f < s) return -1; return 0; } int* numberGame(int* nums, int numsSize, int* returnSize) { ...
.text .globl compar compar: pushq %rbp movq %rsp, %rbp movq %rdi, -24(%rbp) movq %rsi, -32(%rbp) movq -24(%rbp), %rax movl (%rax), %eax movl %eax, -4(%rbp) movq -32(%rbp), %rax movl (%rax), %eax movl %eax, -8(%rbp) movl -4(%rbp), %eax cmpl -8(%rbp), %eax jle .L2 movl $1, %eax jmp .L3 .L2: movl -4(%rbp...
#include <stdio.h> #include <string.h> int strStr(char* a, char* b) { int len = strlen(b); for(int i = 0;i < strlen(a); i++) { char c[len + 1]; strncpy(c, a + i, len); c[len] = '\0'; if (strcmp(c, b) == 0) return i; } return -1; } int main() { char* a1 =...
.text .globl strStr strStr: pushq %rbp movq %rsp, %rbp pushq %r15 pushq %r14 pushq %r13 pushq %r12 pushq %rbx subq $56, %rsp movq %rdi, -88(%rbp) movq %rsi, -96(%rbp) movq -96(%rbp), %rax movq %rax, %rdi call strlen@PLT movl %eax, -56(%rbp) movl $0, -52(%rbp) jmp .L2 .L5: movq %rsp, %rax movq %rax, ...
#include <stdio.h> #include <stdlib.h> int* plusOne(int* digits, int digitsSize, int* returnSize) { int* result = (int*) malloc((digitsSize + 1) * sizeof(int)); for (int i = 0; i < digitsSize; i++) { result[i] = digits[i]; } for (int i = digitsSize - 1; i >= 0; i--) { if (result[i...
.text .globl plusOne plusOne: pushq %rbp movq %rsp, %rbp subq $64, %rsp movq %rdi, -40(%rbp) movl %esi, -44(%rbp) movq %rdx, -56(%rbp) movl -44(%rbp), %eax addl $1, %eax cltq salq $2, %rax movq %rax, %rdi call malloc@PLT movq %rax, -24(%rbp) movl $0, -4(%rbp) jmp .L2 .L3: movl -4(%rbp), %eax cltq le...
#include <stdio.h> int sumRow(int i , int cols,int** accounts){ int s = 0; for(int j = 0; j < cols; j++) { s = s + accounts[i][j]; } return s; } int maximumWealth(int** accounts, int accountsSize, int* accountsColSize) { int max = sumRow(0, *accountsColSize, accounts); int i = 1; ...
.text .globl sumRow sumRow: pushq %rbp movq %rsp, %rbp movl %edi, -20(%rbp) movl %esi, -24(%rbp) movq %rdx, -32(%rbp) movl $0, -4(%rbp) movl $0, -8(%rbp) jmp .L2 .L3: movl -20(%rbp), %eax cltq leaq 0(,%rax,8), %rdx movq -32(%rbp), %rax addq %rdx, %rax movq (%rax), %rax movl -8(%rbp), %edx movslq %edx,...

c2x86 compilation pairs

Pairs of C source files and corresponding x86 assembly.

  • Columns: c (C code), s (x86 assembly)
  • Suggested load:
import json

# JSONL files with one object per line
train = [json.loads(l) for l in open('train.jsonl', 'r', encoding='utf-8')]
test = [json.loads(l) for l in open('test.jsonl', 'r', encoding='utf-8')]
Downloads last month
5