#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 */
scalar_t__ isdigit(char);
int /*<<< orphan*/ skip_space(char **);
int read_int(int *result, char **str) {
  int ok = 0;
  char c;
  (*result) = 0;
  skip_space(str);
  while (isdigit(c = (**str))) {
    ++(*str);
    (*result) *= 10;
    (*result) += c - '0';
    ok = 1;
  }
  skip_space(str);
  return ok;
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <skip_space@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%al
mov    %al,-0x15(%rbp)
movsbl %al,%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     119a <read_int+0x7a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
imul   $0xa,(%rax),%ecx
mov    %ecx,(%rax)
movsbl -0x15(%rbp),%ecx
sub    $0x30,%ecx
mov    -0x8(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
movl   $0x1,-0x14(%rbp)
jmp    114a <read_int+0x2a>
mov    -0x10(%rbp),%rdi
call   1040 <skip_space@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
movl   $0x0,(%rdi)
mov    %rsi,%rdi
call   1040 <skip_space@plt>
mov    (%r14),%rax
mov    (%rax),%bl
movsbl %bl,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1182 <read_int+0x62>
nopl   0x0(%rax,%rax,1)
mov    (%r14),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%r14)
mov    (%r15),%ecx
lea    (%rcx,%rcx,4),%ecx
movsbl %bl,%edx
lea    -0x30(%rdx,%rcx,2),%ecx
mov    %ecx,(%r15)
movzbl 0x1(%rax),%ebx
movsbl %bl,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1150 <read_int+0x30>
mov    $0x1,%ebx
jmp    1184 <read_int+0x64>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1040 <skip_space@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @read_int(i32* nocapture %0, i8** %1) {
store i32 0, i32* %0
%3 = tail call i32 @skip_space(i8** %1)
%4 = load i8*, i8** %1
%5 = load i8, i8* %4
%6 = tail call i64 @isdigit(i8 signext %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %2, %8
%9 = phi i8 [ %17, %8 ], [ %5, %2 ]
%10 = load i8*, i8** %1
%11 = getelementptr inbounds i8, i8* %10, i64 1
store i8* %11, i8** %1
%12 = load i32, i32* %0
%13 = mul nsw i32 %12, 10
%14 = sext i8 %9 to i32
%15 = add nsw i32 %14, -48
%16 = add nsw i32 %15, %13
store i32 %16, i32* %0
%17 = load i8, i8* %11
%18 = tail call i64 @isdigit(i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %8
20: ; preds = %8, %2
%21 = phi i32 [ 0, %2 ], [ 1, %8 ]
%22 = tail call i32 @skip_space(i8** %1)
ret i32 %21
}