#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 atoi_my(char *string) {
  int i = 0;
  int sum = 0;
  printf("\n----func_atoi_my---\n");
  while (i < 100 - 1 && *string != '\0') {
    printf("In step %d sum = %8d; * string = \"%c\" in char, %d as digital and "
           "%p as pointer;\n",
           i, sum, *string, *string, &*string);
    sum = sum * 10 + (*string - '0');
    *string++;
    i++;
    printf("In step %d sum = %8d; * string = \"%c\" in char, %d as digital and "
           "%p as pointer;\n\n",
           i, sum, *string, *string, &*string);
  };
  printf("After cycle sum = %d;\n", sum);
  printf("----end_of_func_atoi_my---\n");
  return sum;
}


x86 assembly (clang, -O0):
<atoi_my>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
cmpl   $0x63,-0xc(%rbp)
mov    %al,-0x11(%rbp)
jge    1157 <atoi_my+0x47>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1167 <atoi_my+0x57>
jmp    11e2 <atoi_my+0xd2>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
mov    -0x8(%rbp),%rax
movsbl (%rax),%r8d
mov    -0x8(%rbp),%r9
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
imul   $0xa,-0x10(%rbp),%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
mov    -0x8(%rbp),%rax
movsbl (%rax),%r8d
mov    -0x8(%rbp),%r9
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1138 <atoi_my+0x28>
mov    -0x10(%rbp),%esi
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atoi_my>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%rbx
lea    0xf87(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r15d
lea    0xebb(%rip),%r12
lea    0xf05(%rip),%r13
xor    %r14d,%r14d
nop
movsbl (%rbx),%ecx
test   %ecx,%ecx
je     11a5 <atoi_my+0x85>
lea    -0x1(%r15),%esi
mov    %r12,%rdi
mov    %r14d,%edx
mov    %ecx,%r8d
mov    %rbx,%r9
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%r14,%r14,4),%eax
movsbl (%rbx),%ecx
lea    (%rcx,%rax,2),%r14d
add    $0xffffffd0,%r14d
movsbl 0x1(%rbx),%ecx
add    $0x1,%rbx
mov    %r13,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
mov    %ecx,%r8d
mov    %rbx,%r9
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15d
cmp    $0x64,%r15d
jne    1150 <atoi_my+0x30>
lea    0xef7(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf12(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"\0A----func_atoi_my---\0A\00"
@.str.1 = [81 x i8] c"In step %d sum = %8d; * string = \22%c\22 in char, %d as digital and %p as pointer;\0A\00"
@.str.2 = [82 x i8] c"In step %d sum = %8d; * string = \22%c\22 in char, %d as digital and %p as pointer;\0A\0A\00"
@.str.3 = [23 x i8] c"After cycle sum = %d;\0A\00"
@.str.4 = [28 x i8] c"----end_of_func_atoi_my---\0A\00"
define i32 @atoi_my(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %16, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 99
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br label %14
14: ; preds = %9, %6
%15 = phi i1 [ false, %6 ], [ %13, %9 ]
br i1 %15, label %16, label %49
16: ; preds = %14
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = load i8*, i8** %2
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = load i8*, i8** %2
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = load i8*, i8** %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18, i32 %21, i32 %24, i8* %25)
%27 = load i32, i32* %4
%28 = mul nsw i32 %27, 10
%29 = load i8*, i8** %2
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = sub nsw i32 %31, 48
%33 = add nsw i32 %28, %32
store i32 %33, i32* %4
%34 = load i8*, i8** %2
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %2
%36 = load i8, i8* %34
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
%39 = load i32, i32* %3
%40 = load i32, i32* %4
%41 = load i8*, i8** %2
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = load i8*, i8** %2
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = load i8*, i8** %2
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0), i32 %39, i32 %40, i32 %43, i32 %46, i8* %47)
br label %6
49: ; preds = %14
%50 = load i32, i32* %4
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
@.str.1 = [81 x i8] c"In step %d sum = %8d; * string = \22%c\22 in char, %d as digital and %p as pointer;\0A\00"
@.str.2 = [82 x i8] c"In step %d sum = %8d; * string = \22%c\22 in char, %d as digital and %p as pointer;\0A\0A\00"
@.str.3 = [23 x i8] c"After cycle sum = %d;\0A\00"
@str = [21 x i8] c"\0A----func_atoi_my---\00"
@str.5 = [27 x i8] c"----end_of_func_atoi_my---\00"
define i32 @atoi_my(i8* %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %3
3: ; preds = %1, %9
%4 = phi i32 [ 0, %1 ], [ %16, %9 ]
%5 = phi i32 [ 0, %1 ], [ %18, %9 ]
%6 = phi i8* [ %0, %1 ], [ %17, %9 ]
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %23, label %9
9: ; preds = %3
%10 = sext i8 %7 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %4, i32 %10, i32 %10, i8* %6)
%12 = mul nsw i32 %4, 10
%13 = load i8, i8* %6
%14 = sext i8 %13 to i32
%15 = add i32 %12, -48
%16 = add i32 %15, %14
%17 = getelementptr inbounds i8, i8* %6, i64 1
%18 = add nuw nsw i32 %5, 1
%19 = load i8, i8* %17
%20 = sext i8 %19 to i32
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %16, i32 %20, i32 %20, i8* %17)
%22 = icmp eq i32 %18, 99
br i1 %22, label %23, label %3
23: ; preds = %9, %3
%24 = phi i32 [ %16, %9 ], [ %4, %3 ]
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
ret i32 %24
}