#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 charToInt(char const);
int fastPower10(int);
int bufferLineToInteger(const char *buffer) {
  int len, value, p;
  len = p = value = 0;
  while (buffer[len] != '\0') {
    len++;
  }
  for (int i = len - 2; i >= 0; i--) {
    value += charToInt(buffer[i]) * fastPower10(p);
    p++;
  }
  return value;
}


x86 assembly (clang, -O0):
<bufferLineToInteger>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1164 <bufferLineToInteger+0x44>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1141 <bufferLineToInteger+0x21>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     11b8 <bufferLineToInteger+0x98>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <charToInt@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <fastPower10@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
imul   %ecx,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    116d <bufferLineToInteger+0x4d>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bufferLineToInteger>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
mov    $0xfffffffd,%ebx
mov    $0xffffffffffffffff,%rax
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmpb   $0x0,0x1(%r12,%rax,1)
lea    0x1(%rax),%rax
jne    1140 <bufferLineToInteger+0x20>
test   $0xfffffffe,%eax
je     119b <bufferLineToInteger+0x7b>
mov    %ebx,%eax
add    $0x1,%ebx
add    %rax,%r12
xor    %ebp,%ebp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%r12),%edi
call   1030 <charToInt@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1040 <fastPower10@plt>
imul   %r15d,%eax
add    %eax,%r14d
add    $0x1,%ebp
add    $0xffffffff,%ebx
add    $0xffffffffffffffff,%r12
test   %ebx,%ebx
jg     1170 <bufferLineToInteger+0x50>
jmp    119e <bufferLineToInteger+0x7e>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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