#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int myatoi(char *);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, const char *arv[]) {
  char unsi[] = "123";
  char si[] = "-123";
  char sl[] = "4444444444";
  char unsl[] = "-4444444444";
  char toolong[] = "4444444444444444";
  printf("signed int=%d\n", myatoi(si));
  printf("unsigned int=%d\n", myatoi(unsi));
  printf("unsigned long=%d\n", myatoi(sl));
  printf("unsigned long=%d\n", myatoi(unsl));
  printf("string too long=%d\n", myatoi(toolong));
  printf("invalid string=%d\n", myatoi("+"));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xec5(%rip),%eax
mov    %eax,-0x14(%rbp)
mov    0xebb(%rip),%eax
mov    %eax,-0x19(%rbp)
mov    0xeb6(%rip),%al
mov    %al,-0x15(%rbp)
mov    0xeae(%rip),%rax
mov    %rax,-0x24(%rbp)
mov    0xeab(%rip),%ax
mov    %ax,-0x1c(%rbp)
mov    0xea3(%rip),%al
mov    %al,-0x1a(%rbp)
mov    0xe8e(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe8c(%rip),%eax
mov    %eax,-0x28(%rbp)
mov    0xed5(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xed2(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xed0(%rip),%al
mov    %al,-0x40(%rbp)
lea    -0x19(%rbp),%rdi
call   1030 <myatoi@plt>
mov    %eax,%esi
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
lea    -0x14(%rbp),%rdi
call   1030 <myatoi@plt>
mov    %eax,%esi
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
lea    -0x24(%rbp),%rdi
call   1030 <myatoi@plt>
mov    %eax,%esi
lea    0xe3f(%rip),%rdi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <myatoi@plt>
mov    %eax,%esi
lea    0xe28(%rip),%rdi
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
call   1030 <myatoi@plt>
mov    %eax,%esi
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
lea    0xe3e(%rip),%rdi
call   1030 <myatoi@plt>
mov    %eax,%esi
lea    0xe1d(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
movl   $0x333231,0xc(%rsp)
movb   $0x0,0x8(%rsp)
movl   $0x3332312d,0x4(%rsp)
33
movabs $0x3434343434343434,%rax
34 34 34
mov    %rax,0x10(%rsp)
movl   $0x343434,0x17(%rsp)
movabs $0x343434343434342d,%rax
34 34 34
mov    %rax,0x20(%rsp)
movl   $0x343434,0x28(%rsp)
movaps 0xef1(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movb   $0x0,0x40(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <myatoi@plt>
lea    0xe89(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0xc(%rsp),%rdi
call   1030 <myatoi@plt>
lea    0xe6f(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0x10(%rsp),%rdi
call   1030 <myatoi@plt>
lea    0xe68(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0x20(%rsp),%rdi
call   1030 <myatoi@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0x30(%rsp),%rdi
call   1030 <myatoi@plt>
lea    0xe4b(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0xe64(%rip),%rdi
call   1030 <myatoi@plt>
lea    0xe45(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.unsi = [4 x i8] c"123\00"
@__const.main.si = [5 x i8] c"-123\00"
@__const.main.sl = [11 x i8] c"4444444444\00"
@__const.main.unsl = [12 x i8] c"-4444444444\00"
@__const.main.toolong = [17 x i8] c"4444444444444444\00"
@.str = [15 x i8] c"signed int=%d\0A\00"
@.str.1 = [17 x i8] c"unsigned int=%d\0A\00"
@.str.2 = [18 x i8] c"unsigned long=%d\0A\00"
@.str.3 = [20 x i8] c"string too long=%d\0A\00"
@.str.4 = [19 x i8] c"invalid string=%d\0A\00"
@.str.5 = [2 x i8] c"+\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i8]
%7 = alloca [5 x i8]
%8 = alloca [11 x i8]
%9 = alloca [12 x i8]
%10 = alloca [17 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [4 x i8]* %6 to i8*
%12 = bitcast [5 x i8]* %7 to i8*
%13 = bitcast [11 x i8]* %8 to i8*
%14 = bitcast [12 x i8]* %9 to i8*
%15 = bitcast [17 x i8]* %10 to i8*
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%17 = call i32 @myatoi(i8* %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%20 = call i32 @myatoi(i8* %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%23 = call i32 @myatoi(i8* %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
%26 = call i32 @myatoi(i8* %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 0
%29 = call i32 @myatoi(i8* %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = call i32 @myatoi(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%32 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %31)
ret i32 0
}

LLVM IR (-O2):
@__const.main.si = [5 x i8] c"-123\00"
@__const.main.sl = [11 x i8] c"4444444444\00"
@__const.main.unsl = [12 x i8] c"-4444444444\00"
@__const.main.toolong = [17 x i8] c"4444444444444444\00"
@.str = [15 x i8] c"signed int=%d\0A\00"
@.str.1 = [17 x i8] c"unsigned int=%d\0A\00"
@.str.2 = [18 x i8] c"unsigned long=%d\0A\00"
@.str.3 = [20 x i8] c"string too long=%d\0A\00"
@.str.4 = [19 x i8] c"invalid string=%d\0A\00"
@.str.5 = [2 x i8] c"+\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [5 x i8]
%5 = alloca [11 x i8]
%6 = alloca [12 x i8]
%7 = alloca [17 x i8]
%8 = bitcast i32* %3 to i8*
store i32 3355185, i32* %3
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%13 = call i32 @myatoi(i8* %9)
%14 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @myatoi(i8* %8)
%16 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i32 @myatoi(i8* %10)
%18 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = call i32 @myatoi(i8* %11)
%20 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = call i32 @myatoi(i8* %12)
%22 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = call i32 @myatoi(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%24 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %23)
ret i32 0
}