#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__ naive_isdigit(char);
scalar_t__ read_char(char *);
int /*<<< orphan*/ read_space();
int /*<<< orphan*/ unread_char(char);
int read_int(int *dp) {
  int flag = 0;
  int d = 0;
  int f = 0;
  char c = '\0';
  read_space();
  read_char(&c);
  if (c == '-')
    f = 1;
  else
    unread_char(c);
  while (read_char(&c) && naive_isdigit(c)) {
    d = d * 10 + (c - '0');
    flag = 1;
  }
  if (c)
    unread_char(c);
  if (flag)
    *dp = f ? -d : d;
  if (!flag && f)
    unread_char('-');
  return flag;
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
mov    $0x0,%al
call   1040 <read_space@plt>
lea    -0x15(%rbp),%rdi
call   1050 <read_char@plt>
movsbl -0x15(%rbp),%eax
cmp    $0x2d,%eax
jne    118e <read_int+0x4e>
movl   $0x1,-0x14(%rbp)
jmp    1197 <read_int+0x57>
movsbl -0x15(%rbp),%edi
call   1060 <unread_char@plt>
jmp    119c <read_int+0x5c>
lea    -0x15(%rbp),%rdi
call   1050 <read_char@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x16(%rbp)
je     11ca <read_int+0x8a>
movsbl -0x15(%rbp),%edi
call   1030 <naive_isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
test   $0x1,%al
jne    11da <read_int+0x9a>
jmp    11f6 <read_int+0xb6>
imul   $0xa,-0x10(%rbp),%eax
movsbl -0x15(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
jmp    119c <read_int+0x5c>
cmpb   $0x0,-0x15(%rbp)
je     1209 <read_int+0xc9>
movsbl -0x15(%rbp),%edi
call   1060 <unread_char@plt>
cmpl   $0x0,-0xc(%rbp)
je     1239 <read_int+0xf9>
cmpl   $0x0,-0x14(%rbp)
je     122a <read_int+0xea>
xor    %eax,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1230 <read_int+0xf0>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0xc(%rbp)
jne    1257 <read_int+0x117>
cmpl   $0x0,-0x14(%rbp)
je     1257 <read_int+0x117>
mov    $0x2d,%edi
call   1060 <unread_char@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movb   $0x0,0xf(%rsp)
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <read_space@plt>
lea    0xf(%rsp),%rdi
call   1050 <read_char@plt>
mov    0xf(%rsp),%r15b
cmp    $0x2d,%r15b
je     117b <read_int+0x3b>
movsbl %r15b,%edi
call   1060 <unread_char@plt>
lea    0xf(%rsp),%rdi
call   1050 <read_char@plt>
mov    $0x1,%r12b
test   %rax,%rax
je     11df <read_int+0x9f>
movsbl 0xf(%rsp),%edi
call   1030 <naive_isdigit@plt>
mov    $0x0,%ebx
test   %rax,%rax
je     11e1 <read_int+0xa1>
xor    %ebx,%ebx
lea    0xf(%rsp),%r12
mov    $0x1,%ebp
nopl   (%rax)
lea    (%rbx,%rbx,4),%eax
movsbl 0xf(%rsp),%ecx
lea    (%rcx,%rax,2),%ebx
add    $0xffffffd0,%ebx
mov    %r12,%rdi
call   1050 <read_char@plt>
test   %rax,%rax
je     11da <read_int+0x9a>
movsbl 0xf(%rsp),%edi
call   1030 <naive_isdigit@plt>
test   %rax,%rax
jne    11b0 <read_int+0x70>
xor    %r12d,%r12d
jmp    11e1 <read_int+0xa1>
xor    %ebx,%ebx
mov    0xf(%rsp),%al
test   %al,%al
je     11f1 <read_int+0xb1>
movsbl %al,%edi
call   1060 <unread_char@plt>
test   %r12b,%r12b
je     1208 <read_int+0xc8>
cmp    $0x2d,%r15b
jne    1216 <read_int+0xd6>
mov    $0x2d,%edi
call   1060 <unread_char@plt>
jmp    1216 <read_int+0xd6>
mov    %ebx,%eax
neg    %eax
cmp    $0x2d,%r15b
cmovne %ebx,%eax
mov    %eax,(%r14)
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_int(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32* %0, i32** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i8 0, i8* %6
%7 = call i32 (...) @read_space()
%8 = call i64 @read_char(i8* %6)
%9 = load i8, i8* %6
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 45
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 1, i32* %5
br label %16
13: ; preds = %1
%14 = load i8, i8* %6
%15 = call i32 @unread_char(i8 signext %14)
br label %16
16: ; preds = %13, %12
br label %17
17: ; preds = %26, %16
%18 = call i64 @read_char(i8* %6)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i8, i8* %6
%22 = call i64 @naive_isdigit(i8 signext %21)
%23 = icmp ne i64 %22, 0
br label %24
24: ; preds = %20, %17
%25 = phi i1 [ false, %17 ], [ %23, %20 ]
br i1 %25, label %26, label %33
26: ; preds = %24
%27 = load i32, i32* %4
%28 = mul nsw i32 %27, 10
%29 = load i8, i8* %6
%30 = sext i8 %29 to i32
%31 = sub nsw i32 %30, 48
%32 = add nsw i32 %28, %31
store i32 %32, i32* %4
store i32 1, i32* %3
br label %17
33: ; preds = %24
%34 = load i8, i8* %6
%35 = icmp ne i8 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i8, i8* %6
%38 = call i32 @unread_char(i8 signext %37)
br label %39
39: ; preds = %36, %33
%40 = load i32, i32* %3
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %53
42: ; preds = %39
%43 = load i32, i32* %5
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i32, i32* %4
%47 = sub nsw i32 0, %46
br label %50
48: ; preds = %42
%49 = load i32, i32* %4
br label %50
50: ; preds = %48, %45
%51 = phi i32 [ %47, %45 ], [ %49, %48 ]
%52 = load i32*, i32** %2
store i32 %51, i32* %52
br label %53
53: ; preds = %50, %39
%54 = load i32, i32* %3
%55 = icmp ne i32 %54, 0
br i1 %55, label %61, label %56
56: ; preds = %53
%57 = load i32, i32* %5
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 @unread_char(i8 signext 45)
br label %61
61: ; preds = %59, %56, %53
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
define i32 @read_int(i32* nocapture writeonly %0) {
%2 = alloca i8
store i8 0, i8* %2
%3 = tail call i32 (...) @read_space()
%4 = call i64 @read_char(i8* %2)
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 45
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i32 @unread_char(i8 signext %5)
br label %9
9: ; preds = %1, %7
%10 = call i64 @read_char(i8* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %29, label %12
12: ; preds = %9
%13 = load i8, i8* %2
%14 = call i64 @naive_isdigit(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %29, label %20
16: ; preds = %20
%17 = load i8, i8* %2
%18 = call i64 @naive_isdigit(i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %12, %16
%21 = phi i32 [ %26, %16 ], [ 0, %12 ]
%22 = mul nsw i32 %21, 10
%23 = load i8, i8* %2
%24 = sext i8 %23 to i32
%25 = add i32 %22, -48
%26 = add i32 %25, %24
%27 = call i64 @read_char(i8* %2)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %16
29: ; preds = %20, %16, %12, %9
%30 = phi i1 [ true, %9 ], [ true, %12 ], [ false, %16 ], [ false, %20 ]
%31 = phi i32 [ 0, %9 ], [ 0, %12 ], [ 1, %16 ], [ 1, %20 ]
%32 = phi i32 [ 0, %9 ], [ 0, %12 ], [ %26, %16 ], [ %26, %20 ]
%33 = load i8, i8* %2
%34 = icmp eq i8 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %29
%36 = call i32 @unread_char(i8 signext %33)
br label %37
37: ; preds = %35, %29
br i1 %30, label %41, label %38
38: ; preds = %37
%39 = sub nsw i32 0, %32
%40 = select i1 %6, i32 %39, i32 %32
store i32 %40, i32* %0
br label %44
41: ; preds = %37
br i1 %6, label %42, label %44
42: ; preds = %41
%43 = call i32 @unread_char(i8 signext 45)
br label %44
44: ; preds = %38, %42, %41
ret i32 %31
}