#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 */
scalar_t__ isdigit(unsigned char);
scalar_t__ isspace(unsigned char);
int my_atoi(char *s) {
  int val = 0, sign;
  for (; isspace((unsigned char)*s); s++)
    ;
  sign = (*s == '-' ? -1 : 1);
  if (*s == '-' || *s == '+')
    s++;
  while (isdigit((unsigned char)*s)) {
    val = val * 10 + *s - '0';
    s++;
  }
  return sign * val;
}


x86 assembly (clang, -O0):
<my_atoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     115f <my_atoi+0x3f>
jmp    114e <my_atoi+0x2e>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1133 <my_atoi+0x13>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edx
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    $0x2d,%edx
cmove  %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     1199 <my_atoi+0x79>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    11a5 <my_atoi+0x85>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11aa <my_atoi+0x8a>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11e4 <my_atoi+0xc4>
imul   $0xa,-0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11aa <my_atoi+0x8a>
mov    -0x10(%rbp),%eax
imul   -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_atoi>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%edi
call   1040 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1130 <my_atoi+0x10>
mov    -0x1(%rbx),%r14b
lea    -0x2b(%r14),%eax
xor    %r15d,%r15d
test   $0xfd,%al
sete   %r15b
movzbl -0x1(%rbx,%r15,1),%edi
call   1030 <isdigit@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     1195 <my_atoi+0x75>
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%r12,%r12,4),%eax
movsbl -0x1(%rbx,%r15,1),%ecx
lea    (%rcx,%rax,2),%r12d
add    $0xffffffd0,%r12d
movzbl (%rbx,%r15,1),%edi
call   1030 <isdigit@plt>
add    $0x1,%r15
test   %rax,%rax
jne    1170 <my_atoi+0x50>
mov    %r12d,%eax
neg    %eax
cmp    $0x2d,%r14b
cmovne %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @my_atoi(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %5
5: ; preds = %11, %1
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = call i64 @isspace(i8 zeroext %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %5
br label %11
11: ; preds = %10
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %2
br label %5
14: ; preds = %5
%15 = load i8*, i8** %2
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 45
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 -1, i32 1
store i32 %20, i32* %4
%21 = load i8*, i8** %2
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 45
br i1 %24, label %30, label %25
25: ; preds = %14
%26 = load i8*, i8** %2
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 43
br i1 %29, label %30, label %33
30: ; preds = %25, %14
%31 = load i8*, i8** %2
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %2
br label %33
33: ; preds = %30, %25
br label %34
34: ; preds = %39, %33
%35 = load i8*, i8** %2
%36 = load i8, i8* %35
%37 = call i64 @isdigit(i8 zeroext %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %34
%40 = load i32, i32* %3
%41 = mul nsw i32 %40, 10
%42 = load i8*, i8** %2
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = add nsw i32 %41, %44
%46 = sub nsw i32 %45, 48
store i32 %46, i32* %3
%47 = load i8*, i8** %2
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %2
br label %34
49: ; preds = %34
%50 = load i32, i32* %4
%51 = load i32, i32* %3
%52 = mul nsw i32 %50, %51
ret i32 %52
}

LLVM IR (-O2):
define i32 @my_atoi(i8* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %7, %2 ]
%4 = load i8, i8* %3
%5 = tail call i64 @isspace(i8 zeroext %4)
%6 = icmp eq i64 %5, 0
%7 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %6, label %8, label %2
8: ; preds = %2
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 45
%11 = icmp eq i8 %9, 43
%12 = or i1 %10, %11
%13 = zext i1 %12 to i64
%14 = getelementptr i8, i8* %3, i64 %13
%15 = load i8, i8* %14
%16 = tail call i64 @isdigit(i8 zeroext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %30, label %18
18: ; preds = %8, %18
%19 = phi i8* [ %26, %18 ], [ %14, %8 ]
%20 = phi i32 [ %25, %18 ], [ 0, %8 ]
%21 = mul nsw i32 %20, 10
%22 = load i8, i8* %19
%23 = sext i8 %22 to i32
%24 = add i32 %21, -48
%25 = add i32 %24, %23
%26 = getelementptr inbounds i8, i8* %19, i64 1
%27 = load i8, i8* %26
%28 = tail call i64 @isdigit(i8 zeroext %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %18
30: ; preds = %18, %8
%31 = phi i32 [ 0, %8 ], [ %25, %18 ]
%32 = sub nsw i32 0, %31
%33 = select i1 %10, i32 %32, i32 %31
ret i32 %33
}