#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 power(int, int);
int parse_int(char *num) {
  int i;
  int exp = 0;
  int sum = 0;
  while (num[i++] != '\0') {
  }
  i -= 2;
  while (i >= 0) {
    sum += ((int)num[i] - 48) * power(10, exp);
    exp += 1;
    i--;
  }
  return sum;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     114e <parse_int+0x3e>
jmp    112a <parse_int+0x1a>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11a5 <parse_int+0x95>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sub    $0x30,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%esi
mov    $0xa,%edi
call   1030 <power@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
imul   %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1157 <parse_int+0x47>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,(%rdi,%r15,1)
lea    0x1(%r15),%r15
jne    1130 <parse_int+0x20>
lea    -0x1(%r15),%rax
test   %eax,%eax
jle    119d <parse_int+0x8d>
mov    %eax,%eax
add    $0xffffffffffffffff,%rax
mov    %rax,0x8(%rsp)
xor    %r12d,%r12d
xor    %ebp,%ebp
xor    %ebx,%ebx
xor    %r13d,%r13d
mov    %rdi,0x10(%rsp)
nopl   (%rax)
mov    0x8(%rsp),%rax
add    %r12d,%eax
movsbl (%rdi,%rax,1),%r14d
add    $0xffffffd0,%r14d
mov    $0xa,%edi
mov    %ebx,%esi
call   1030 <power@plt>
mov    0x10(%rsp),%rdi
imul   %r14d,%eax
add    %eax,%ebp
add    $0x1,%ebx
add    $0xffffffffffffffff,%r13
lea    (%r15,%r12,1),%eax
mov    %r13,%r12
cmp    $0x2,%eax
jne    1160 <parse_int+0x50>
jmp    119f <parse_int+0x8f>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @parse_int(i8* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ %4, %2 ], [ 0, %1 ]
%4 = add i64 %3, 1
%5 = getelementptr inbounds i8, i8* %0, i64 %3
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %2
8: ; preds = %2
%9 = trunc i64 %3 to i32
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = and i64 %3, 4294967295
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ %12, %11 ], [ %17, %13 ]
%15 = phi i32 [ 0, %11 ], [ %25, %13 ]
%16 = phi i32 [ 0, %11 ], [ %26, %13 ]
%17 = add nsw i64 %14, -1
%18 = and i64 %17, 4294967295
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = add nsw i32 %21, -48
%23 = tail call i32 @power(i32 10, i32 %16)
%24 = mul nsw i32 %22, %23
%25 = add nsw i32 %24, %15
%26 = add nuw nsw i32 %16, 1
%27 = icmp eq i32 %26, %9
br i1 %27, label %28, label %13
28: ; preds = %13, %8
%29 = phi i32 [ 0, %8 ], [ %25, %13 ]
ret i32 %29
}