#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*/ printf(char *, int);
int atoi(char s[]) {
  int i, n;
  n = 0;
  for (i = 0; s[i] >= '0' && s[i] <= '9'; ++i) {
    n = 10 * n + (s[i] - '0');
    printf("%d here is the number", n);
  }
  return n;
}


x86 assembly (clang, -O0):
<atoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x11(%rbp)
jl     1159 <atoi+0x49>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1169 <atoi+0x59>
jmp    119e <atoi+0x8e>
imul   $0xa,-0x10(%rbp),%eax
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112a <atoi+0x1a>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atoi>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%al
lea    -0x30(%rax),%ecx
xor    %r14d,%r14d
cmp    $0x9,%cl
ja     1169 <atoi+0x59>
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %r14d,%r14d
lea    0xecd(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl %al,%eax
lea    (%r14,%r14,4),%ecx
lea    (%rax,%rcx,2),%r14d
add    $0xffffffd0,%r14d
mov    %r15,%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
movzbl (%rbx),%eax
lea    -0x30(%rax),%ecx
add    $0x1,%rbx
cmp    $0xa,%cl
jb     1140 <atoi+0x30>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"%d here is the number\00"
define i32 @atoi(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
store i32 0, i32* %3
br label %5
5: ; preds = %36, %1
%6 = load i8*, i8** %2
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp sge i32 %11, 48
br i1 %12, label %13, label %21
13: ; preds = %5
%14 = load i8*, i8** %2
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp sle i32 %19, 57
br label %21
21: ; preds = %13, %5
%22 = phi i1 [ false, %5 ], [ %20, %13 ]
br i1 %22, label %23, label %39
23: ; preds = %21
%24 = load i32, i32* %4
%25 = mul nsw i32 10, %24
%26 = load i8*, i8** %2
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = sub nsw i32 %31, 48
%33 = add nsw i32 %25, %32
store i32 %33, i32* %4
%34 = load i32, i32* %4
%35 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %23
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %5
39: ; preds = %21
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@.str = [22 x i8] c"%d here is the number\00"
define i32 @atoi(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = add i8 %2, -48
%4 = icmp ult i8 %3, 10
br i1 %4, label %5, label %19
5: ; preds = %1, %5
%6 = phi i64 [ %14, %5 ], [ 0, %1 ]
%7 = phi i8 [ %16, %5 ], [ %2, %1 ]
%8 = phi i32 [ %12, %5 ], [ 0, %1 ]
%9 = zext i8 %7 to i32
%10 = mul nsw i32 %8, 10
%11 = add i32 %10, -48
%12 = add i32 %11, %9
%13 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = add nuw i64 %6, 1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = add i8 %16, -48
%18 = icmp ult i8 %17, 10
br i1 %18, label %5, label %19
19: ; preds = %5, %1
%20 = phi i32 [ 0, %1 ], [ %12, %5 ]
ret i32 %20
}