#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 /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ isdigit(char const);
int my_atoi(const char *str) {
  int value = 0;
  int sign = 1;
  assert(str != NULL);
  if (*str == '-') {
    sign = -1;
    str++;
  } else if (*str == '+') {
    sign = 1;
    str++;
  }
  int temp = 0;
  while (isdigit(*str)) {
    temp = *str - '0';
    value = 10 * value + temp;
    str++;
  }
  return value * sign;
}


x86 assembly (clang, -O0):
<my_atoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1174 <my_atoi+0x54>
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    119c <my_atoi+0x7c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    1197 <my_atoi+0x77>
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    119c <my_atoi+0x7c>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11e1 <my_atoi+0xc1>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
imul   $0xa,-0xc(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11a3 <my_atoi+0x83>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_atoi>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
mov    (%rbx),%al
mov    $0x1,%ebp
cmp    $0x2b,%al
je     114f <my_atoi+0x2f>
cmp    $0x2d,%al
jne    1153 <my_atoi+0x33>
add    $0x1,%rbx
mov    $0xffffffff,%ebp
jmp    1153 <my_atoi+0x33>
add    $0x1,%rbx
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1193 <my_atoi+0x73>
add    $0x1,%rbx
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
movsbl -0x1(%rbx),%eax
lea    (%r14,%r14,4),%ecx
lea    (%rax,%rcx,2),%r14d
add    $0xffffffd0,%r14d
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1170 <my_atoi+0x50>
jmp    1196 <my_atoi+0x76>
xor    %r14d,%r14d
imul   %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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