int atoi(const char *s) {
  _Bool negative;
  int value;
  if (s != ((void *)0)) {
  } else {
    debug_panic("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/Coding-Headache/CNOS/refs/"
                "heads/master/OS_Dev/pintos/lib/stdlib.c",
                15, __func__, "assertion `%s' failed.", "s != NULL");
  };
  while (isspace((unsigned char)*s))
    s++;
  negative = 0;
  if (*s == '+')
    s++;
  else if (*s == '-') {
    negative = 1;
    s++;
  }
  for (value = 0; isdigit(*s); s++)
    value = value * 10 - (*s - '0');
  if (!negative)
    value = -value;
  return value;
}


x86 assembly (clang, -O0):
<atoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     114c <atoi+0x1c>
jmp    1174 <atoi+0x44>
lea    0xead(%rip),%rdi
mov    $0xf,%esi
lea    0xf3d(%rip),%rdx
lea    0xf3b(%rip),%rcx
lea    0xf4b(%rip),%r8
mov    $0x0,%al
call   1040 <debug_panic@plt>
jmp    1179 <atoi+0x49>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%eax
je     119f <atoi+0x6f>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1179 <atoi+0x49>
movb   $0x0,-0x9(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    11c4 <atoi+0x94>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11e9 <atoi+0xb9>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11e4 <atoi+0xb4>
movb   $0x1,-0x9(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11e9 <atoi+0xb9>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     1229 <atoi+0xf9>
imul   $0xa,-0x10(%rbp),%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
sub    $0x30,%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11f0 <atoi+0xc0>
testb  $0x1,-0x9(%rbp)
jne    123b <atoi+0x10b>
xor    %eax,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atoi>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
jne    1160 <atoi+0x40>
lea    0xecd(%rip),%rdi
lea    0xf62(%rip),%rdx
lea    0xf60(%rip),%rcx
lea    0xf70(%rip),%r8
mov    $0xf,%esi
xor    %eax,%eax
call   1030 <debug_panic@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r14),%ebx
movzbl %bl,%edi
call   1040 <isspace@plt>
add    $0x1,%r14
test   %eax,%eax
jne    1160 <atoi+0x40>
cmp    $0x2b,%bl
je     1186 <atoi+0x66>
cmp    $0x2d,%bl
jne    1182 <atoi+0x62>
mov    $0x1,%cl
jmp    1188 <atoi+0x68>
add    $0xffffffffffffffff,%r14
xor    %ecx,%ecx
movsbl (%r14),%eax
add    $0xffffffd0,%eax
xor    %edx,%edx
cmp    $0x9,%eax
ja     11b7 <atoi+0x97>
add    $0x1,%r14
xor    %edx,%edx
nopl   0x0(%rax)
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
sub    %eax,%edx
movsbl (%r14),%eax
add    $0xffffffd0,%eax
add    $0x1,%r14
cmp    $0xa,%eax
jb     11a0 <atoi+0x80>
mov    %edx,%eax
neg    %eax
test   %cl,%cl
cmovne %edx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [156 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Coding-Headache/CNOS/refs/heads/master/OS_Dev/pintos/lib/stdlib.c\00"
@__func__.atoi = [5 x i8] c"atoi\00"
@.str.1 = [23 x i8] c"assertion `%s' failed.\00"
@.str.2 = [10 x i8] c"s != NULL\00"
define i32 @atoi(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
br label %10
8: ; preds = %1
%9 = call i32 (i8*, i32, i8*, i8*, i8*, ...) bitcast (i32 (...)* @debug_panic to i32 (i8*, i32, i8*, i8*, i8*, ...)*)(i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str, i64 0, i64 0), i32 15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__func__.atoi, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %7
br label %11
11: ; preds = %17, %10
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = call i32 @isspace(i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i8*, i8** %2
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %2
br label %11
20: ; preds = %11
store i8 0, i8* %3
%21 = load i8*, i8** %2
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 43
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i8*, i8** %2
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %2
br label %37
28: ; preds = %20
%29 = load i8*, i8** %2
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 45
br i1 %32, label %33, label %36
33: ; preds = %28
store i8 1, i8* %3
%34 = load i8*, i8** %2
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %2
br label %36
36: ; preds = %33, %28
br label %37
37: ; preds = %36, %25
store i32 0, i32* %4
br label %38
38: ; preds = %52, %37
%39 = load i8*, i8** %2
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = call i32 @isdigit(i32 %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %55
44: ; preds = %38
%45 = load i32, i32* %4
%46 = mul nsw i32 %45, 10
%47 = load i8*, i8** %2
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = sub nsw i32 %49, 48
%51 = sub nsw i32 %46, %50
store i32 %51, i32* %4
br label %52
52: ; preds = %44
%53 = load i8*, i8** %2
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %2
br label %38
55: ; preds = %38
%56 = load i8, i8* %3
%57 = trunc i8 %56 to i1
br i1 %57, label %61, label %58
58: ; preds = %55
%59 = load i32, i32* %4
%60 = sub nsw i32 0, %59
store i32 %60, i32* %4
br label %61
61: ; preds = %58, %55
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
@.str = [156 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Coding-Headache/CNOS/refs/heads/master/OS_Dev/pintos/lib/stdlib.c\00"
@__func__.atoi = [5 x i8] c"atoi\00"
@.str.1 = [23 x i8] c"assertion `%s' failed.\00"
@.str.2 = [10 x i8] c"s != NULL\00"
define i32 @atoi(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 (i8*, i32, i8*, i8*, i8*, ...) bitcast (i32 (...)* @debug_panic to i32 (i8*, i32, i8*, i8*, i8*, ...)*)(i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str, i64 0, i64 0), i32 15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__func__.atoi, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %5
5: ; preds = %1, %3
br label %6
6: ; preds = %5, %6
%7 = phi i8* [ %12, %6 ], [ %0, %5 ]
%8 = load i8, i8* %7
%9 = zext i8 %8 to i32
%10 = tail call i32 @isspace(i32 %9)
%11 = icmp eq i32 %10, 0
%12 = getelementptr inbounds i8, i8* %7, i64 1
br i1 %11, label %13, label %6
13: ; preds = %6
switch i8 %8, label %16 [
i8 43, label %14
i8 45, label %15
]
14: ; preds = %13
br label %16
15: ; preds = %13
br label %16
16: ; preds = %13, %15, %14
%17 = phi i8* [ %12, %14 ], [ %12, %15 ], [ %7, %13 ]
%18 = phi i1 [ false, %14 ], [ true, %15 ], [ false, %13 ]
%19 = load i8, i8* %17
%20 = sext i8 %19 to i32
%21 = add nsw i32 %20, -48
%22 = icmp ult i32 %21, 10
br i1 %22, label %23, label %34
23: ; preds = %16, %23
%24 = phi i32 [ %32, %23 ], [ %21, %16 ]
%25 = phi i32 [ %28, %23 ], [ 0, %16 ]
%26 = phi i8* [ %29, %23 ], [ %17, %16 ]
%27 = mul nsw i32 %25, 10
%28 = sub nsw i32 %27, %24
%29 = getelementptr inbounds i8, i8* %26, i64 1
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = add nsw i32 %31, -48
%33 = icmp ult i32 %32, 10
br i1 %33, label %23, label %34
34: ; preds = %23, %16
%35 = phi i32 [ 0, %16 ], [ %28, %23 ]
%36 = sub nsw i32 0, %35
%37 = select i1 %18, i32 %35, i32 %36
ret i32 %37
}