#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 */
char getchar();
void scan_int(int *x) {
  register int s = 0;
  int neg = 0;
  char c;
  for (c = getchar(); (c < 48 && c > 57); c = getchar()) {
    if (c == '-') {
      neg = 1;
      c = getchar();
      break;
    }
  }
  for (; c >= 48 && c <= 57; c = getchar()) {
    s += (s << 1) + (s << 3) + (c - 48);
  }
  if (neg) {
    s = -s;
  }
  *x = s;
}


x86 assembly (clang, -O0):
<scan_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x12(%rbp)
jge    1153 <scan_int+0x43>
movsbl -0x11(%rbp),%eax
cmp    $0x39,%eax
setg   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    1163 <scan_int+0x53>
jmp    119a <scan_int+0x8a>
movsbl -0x11(%rbp),%eax
cmp    $0x2d,%eax
jne    1186 <scan_int+0x76>
movl   $0x1,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x11(%rbp)
jmp    119a <scan_int+0x8a>
jmp    118b <scan_int+0x7b>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x11(%rbp)
jmp    1134 <scan_int+0x24>
jmp    119f <scan_int+0x8f>
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x13(%rbp)
jl     11be <scan_int+0xae>
movsbl -0x11(%rbp),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%al
test   $0x1,%al
jne    11ce <scan_int+0xbe>
jmp    11fa <scan_int+0xea>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    -0xc(%rbp),%ecx
shl    $0x3,%ecx
add    %ecx,%eax
movsbl -0x11(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x11(%rbp)
jmp    119f <scan_int+0x8f>
cmpl   $0x0,-0x10(%rbp)
je     120c <scan_int+0xfc>
xor    %eax,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_int>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
lea    -0x30(%rax),%ecx
cmp    $0x9,%cl
ja     1150 <scan_int+0x40>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl %al,%eax
lea    (%rbx,%rbx,4),%ecx
lea    (%rbx,%rcx,2),%ecx
lea    (%rax,%rcx,1),%ebx
add    $0xffffffd0,%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %eax,%ecx
add    $0xd0,%cl
cmp    $0xa,%cl
jb     1130 <scan_int+0x20>
mov    %ebx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @scan_int(i32* nocapture writeonly %0) {
%2 = tail call signext i8 (...) @getchar()
%3 = add i8 %2, -48
%4 = icmp ult i8 %3, 10
br i1 %4, label %5, label %16
5: ; preds = %1, %5
%6 = phi i8 [ %13, %5 ], [ %2, %1 ]
%7 = phi i32 [ %12, %5 ], [ 0, %1 ]
%8 = zext i8 %6 to i32
%9 = mul i32 %7, 10
%10 = add i32 %7, -48
%11 = add i32 %10, %9
%12 = add i32 %11, %8
%13 = tail call signext i8 (...) @getchar()
%14 = add i8 %13, -48
%15 = icmp ult i8 %14, 10
br i1 %15, label %5, label %16
16: ; preds = %5, %1
%17 = phi i32 [ 0, %1 ], [ %12, %5 ]
store i32 %17, i32* %0
ret void
}