#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 atoi(char *);
scalar_t__ digit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getc(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/);
int read_int(char first) {
  char buf[11];
  int peek, i;
  buf[0] = first;
  buf[10] = '\0';
  for (i = 1; i < 10; i++) {
    peek = getc(stdin);
    if (digit(peek)) {
      buf[i] = peek;
    } else {
      buf[i] = '\0';
      break;
    }
  }
  if (i == 10) {
    peek = getc(stdin);
    if (digit(peek)) {
      fprintf(stderr, "integer constant has too many digits\n");
      return -10;
    }
  }
  ungetc(peek, stdin);
  return atoi(buf);
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
mov    %al,-0x10(%rbp)
movb   $0x0,-0x6(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    11cf <read_int+0x7f>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
call   1070 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <digit@plt>
cmp    $0x0,%rax
je     11ae <read_int+0x5e>
mov    -0x14(%rbp),%eax
mov    %al,%cl
movslq -0x18(%rbp),%rax
mov    %cl,-0x10(%rbp,%rax,1)
jmp    11bc <read_int+0x6c>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x10(%rbp,%rax,1)
jmp    11cf <read_int+0x7f>
jmp    11c1 <read_int+0x71>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116f <read_int+0x1f>
cmpl   $0xa,-0x18(%rbp)
jne    1222 <read_int+0xd2>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1070 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <digit@plt>
cmp    $0x0,%rax
je     121d <read_int+0xcd>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xfffffff6,-0x4(%rbp)
jmp    123f <read_int+0xef>
jmp    1222 <read_int+0xd2>
mov    -0x14(%rbp),%edi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
call   1050 <ungetc@plt>
lea    -0x10(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %dil,0xd(%rsp)
movb   $0x0,0x17(%rsp)
mov    0x2e80(%rip),%r14
mov    (%r14),%edi
call   1070 <getc@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <digit@plt>
test   %rax,%rax
je     12a4 <read_int+0x154>
mov    %bl,0xe(%rsp)
mov    (%r14),%edi
call   1070 <getc@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <digit@plt>
test   %rax,%rax
je     12ab <read_int+0x15b>
mov    %bl,0xf(%rsp)
mov    (%r14),%edi
call   1070 <getc@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <digit@plt>
test   %rax,%rax
je     12b2 <read_int+0x162>
mov    %bl,0x10(%rsp)
mov    (%r14),%edi
call   1070 <getc@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <digit@plt>
test   %rax,%rax
je     12b9 <read_int+0x169>
mov    %bl,0x11(%rsp)
mov    (%r14),%edi
call   1070 <getc@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <digit@plt>
test   %rax,%rax
je     12c0 <read_int+0x170>
mov    %bl,0x12(%rsp)
mov    (%r14),%edi
call   1070 <getc@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <digit@plt>
test   %rax,%rax
je     12c7 <read_int+0x177>
mov    %bl,0x13(%rsp)
mov    (%r14),%edi
call   1070 <getc@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <digit@plt>
test   %rax,%rax
je     12ce <read_int+0x17e>
mov    %bl,0x14(%rsp)
mov    (%r14),%edi
call   1070 <getc@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <digit@plt>
test   %rax,%rax
je     12d5 <read_int+0x185>
mov    %bl,0x15(%rsp)
mov    (%r14),%edi
call   1070 <getc@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <digit@plt>
test   %rax,%rax
je     12dc <read_int+0x18c>
mov    %bl,0x16(%rsp)
mov    (%r14),%edi
call   1070 <getc@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <digit@plt>
test   %rax,%rax
je     12e6 <read_int+0x196>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xfffffff6,%eax
jmp    12fa <read_int+0x1aa>
mov    $0x1,%eax
jmp    12e1 <read_int+0x191>
mov    $0x2,%eax
jmp    12e1 <read_int+0x191>
mov    $0x3,%eax
jmp    12e1 <read_int+0x191>
mov    $0x4,%eax
jmp    12e1 <read_int+0x191>
mov    $0x5,%eax
jmp    12e1 <read_int+0x191>
mov    $0x6,%eax
jmp    12e1 <read_int+0x191>
mov    $0x7,%eax
jmp    12e1 <read_int+0x191>
mov    $0x8,%eax
jmp    12e1 <read_int+0x191>
mov    $0x9,%eax
movb   $0x0,0xd(%rsp,%rax,1)
mov    (%r14),%esi
mov    %ebx,%edi
call   1050 <ungetc@plt>
lea    0xd(%rsp),%rdi
call   1060 <atoi@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"integer constant has too many digits\0A\00"
define i32 @read_int(i8 signext %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca [11 x i8]
%5 = alloca i32
%6 = alloca i32
store i8 %0, i8* %3
%7 = load i8, i8* %3
%8 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
store i8 %7, i8* %8
%9 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 10
store i8 0, i8* %9
store i32 1, i32* %6
br label %10
10: ; preds = %30, %1
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 10
br i1 %12, label %13, label %33
13: ; preds = %10
%14 = load i32, i32* @stdin
%15 = call i32 @getc(i32 %14)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = call i64 @digit(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %13
%20 = load i32, i32* %5
%21 = trunc i32 %20 to i8
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 %23
store i8 %21, i8* %24
br label %29
25: ; preds = %13
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 %27
store i8 0, i8* %28
br label %33
29: ; preds = %19
br label %30
30: ; preds = %29
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %10
33: ; preds = %25, %10
%34 = load i32, i32* %6
%35 = icmp eq i32 %34, 10
br i1 %35, label %36, label %46
36: ; preds = %33
%37 = load i32, i32* @stdin
%38 = call i32 @getc(i32 %37)
store i32 %38, i32* %5
%39 = load i32, i32* %5
%40 = call i64 @digit(i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 -10, i32* %2
br label %52
45: ; preds = %36
br label %46
46: ; preds = %45, %33
%47 = load i32, i32* %5
%48 = load i32, i32* @stdin
%49 = call i32 @ungetc(i32 %47, i32 %48)
%50 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%51 = call i32 @atoi(i8* %50)
store i32 %51, i32* %2
br label %52
52: ; preds = %46, %42
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
@stdin = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"integer constant has too many digits\0A\00"
define i32 @read_int(i8 signext %0) {
%2 = alloca [11 x i8]
%3 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
store i8 %0, i8* %3
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 10
store i8 0, i8* %4
%5 = load i32, i32* @stdin
%6 = tail call i32 @getc(i32 %5)
%7 = tail call i64 @digit(i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %65, label %9
9: ; preds = %1
%10 = trunc i32 %6 to i8
%11 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 1
store i8 %10, i8* %11
%12 = load i32, i32* @stdin
%13 = tail call i32 @getc(i32 %12)
%14 = tail call i64 @digit(i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %65, label %16
16: ; preds = %9
%17 = trunc i32 %13 to i8
%18 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 2
store i8 %17, i8* %18
%19 = load i32, i32* @stdin
%20 = tail call i32 @getc(i32 %19)
%21 = tail call i64 @digit(i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %65, label %23
23: ; preds = %16
%24 = trunc i32 %20 to i8
%25 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 3
store i8 %24, i8* %25
%26 = load i32, i32* @stdin
%27 = tail call i32 @getc(i32 %26)
%28 = tail call i64 @digit(i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %65, label %30
30: ; preds = %23
%31 = trunc i32 %27 to i8
%32 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 4
store i8 %31, i8* %32
%33 = load i32, i32* @stdin
%34 = tail call i32 @getc(i32 %33)
%35 = tail call i64 @digit(i32 %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %65, label %37
37: ; preds = %30
%38 = trunc i32 %34 to i8
%39 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 5
store i8 %38, i8* %39
%40 = load i32, i32* @stdin
%41 = tail call i32 @getc(i32 %40)
%42 = tail call i64 @digit(i32 %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %65, label %44
44: ; preds = %37
%45 = trunc i32 %41 to i8
%46 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 6
store i8 %45, i8* %46
%47 = load i32, i32* @stdin
%48 = tail call i32 @getc(i32 %47)
%49 = tail call i64 @digit(i32 %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %65, label %51
51: ; preds = %44
%52 = trunc i32 %48 to i8
%53 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 7
store i8 %52, i8* %53
%54 = load i32, i32* @stdin
%55 = tail call i32 @getc(i32 %54)
%56 = tail call i64 @digit(i32 %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %65, label %58
58: ; preds = %51
%59 = trunc i32 %55 to i8
%60 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 8
store i8 %59, i8* %60
%61 = load i32, i32* @stdin
%62 = tail call i32 @getc(i32 %61)
%63 = tail call i64 @digit(i32 %62)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %58, %51, %44, %37, %30, %23, %16, %9, %1
%66 = phi i64 [ 1, %1 ], [ 2, %9 ], [ 3, %16 ], [ 4, %23 ], [ 5, %30 ], [ 6, %37 ], [ 7, %44 ], [ 8, %51 ], [ 9, %58 ]
%67 = phi i32 [ %6, %1 ], [ %13, %9 ], [ %20, %16 ], [ %27, %23 ], [ %34, %30 ], [ %41, %37 ], [ %48, %44 ], [ %55, %51 ], [ %62, %58 ]
%68 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 %66
store i8 0, i8* %68
br label %79
69: ; preds = %58
%70 = trunc i32 %62 to i8
%71 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 9
store i8 %70, i8* %71
%72 = load i32, i32* @stdin
%73 = tail call i32 @getc(i32 %72)
%74 = tail call i64 @digit(i32 %73)
%75 = icmp eq i64 %74, 0
br i1 %75, label %79, label %76
76: ; preds = %69
%77 = load i32, i32* @stderr
%78 = tail call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %84
79: ; preds = %65, %69
%80 = phi i32 [ %73, %69 ], [ %67, %65 ]
%81 = load i32, i32* @stdin
%82 = tail call i32 @ungetc(i32 %80, i32 %81)
%83 = call i32 @atoi(i8* %3)
br label %84
84: ; preds = %79, %76
%85 = phi i32 [ -10, %76 ], [ %83, %79 ]
ret i32 %85
}