#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 */
typedef int uint64_t;

/* Variables and functions */
int LONG_MAX;
char getchar();
scalar_t__ is_digit(char);
int /*<<< orphan*/ printf(char *);
long get_long() {
  printf("> ");
  uint64_t l = 0;
  char c = 0;
  while (!is_digit(c))
    c = getchar();
  while (is_digit(c)) {
    if (l >= LONG_MAX) {
      l = LONG_MAX;
      break;
    }
    l *= 10;
    l += c - '0';
    c = getchar();
  }
  while (c != '\n')
    c = getchar();
  return l;
}


x86 assembly (clang, -O0):
<get_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1050 <is_digit@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    116e <get_long+0x3e>
jmp    117d <get_long+0x4d>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x5(%rbp)
jmp    114f <get_long+0x1f>
jmp    1182 <get_long+0x52>
movsbl -0x5(%rbp),%edi
call   1050 <is_digit@plt>
cmp    $0x0,%rax
je     11db <get_long+0xab>
mov    -0x4(%rbp),%eax
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%eax
jl     11b8 <get_long+0x88>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11db <get_long+0xab>
imul   $0xa,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x5(%rbp)
jmp    1182 <get_long+0x52>
jmp    11e0 <get_long+0xb0>
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
je     11fc <get_long+0xcc>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x5(%rbp)
jmp    11e0 <get_long+0xb0>
movslq -0x4(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_long>:
push   %r15
push   %r14
push   %rbx
lea    0xec4(%rip),%rdi
call   1030 <printf@plt>
xor    %r14d,%r14d
xor    %edi,%edi
call   1050 <is_digit@plt>
mov    $0x0,%ebx
test   %rax,%rax
jne    1176 <get_long+0x46>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
movsbl %al,%edi
call   1050 <is_digit@plt>
test   %rax,%rax
je     1160 <get_long+0x30>
movsbl %bl,%edi
call   1050 <is_digit@plt>
test   %rax,%rax
je     11bd <get_long+0x8d>
mov    0x2e56(%rip),%r15
xor    %r14d,%r14d
nopl   (%rax)
mov    (%r15),%eax
cmp    %eax,%r14d
jge    11e4 <get_long+0xb4>
lea    (%r14,%r14,4),%eax
movsbl %bl,%ecx
lea    (%rcx,%rax,2),%r14d
add    $0xffffffd0,%r14d
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
movsbl %al,%edi
call   1050 <is_digit@plt>
test   %rax,%rax
jne    1190 <get_long+0x60>
cmp    $0xa,%bl
je     11db <get_long+0xab>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    11d0 <get_long+0xa0>
movslq %r14d,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %eax,%r14d
cmp    $0xa,%bl
jne    11d0 <get_long+0xa0>
jmp    11db <get_long+0xab>

LLVM IR (-O0):
@.str = [3 x i8] c"> \00"
@LONG_MAX = global i32 0
define i64 @get_long() {
%1 = alloca i32
%2 = alloca i8
%3 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
store i8 0, i8* %2
br label %4
4: ; preds = %9, %0
%5 = load i8, i8* %2
%6 = call i64 @is_digit(i8 signext %5)
%7 = icmp ne i64 %6, 0
%8 = xor i1 %7, true
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = call signext i8 (...) @getchar()
store i8 %10, i8* %2
br label %4
11: ; preds = %4
br label %12
12: ; preds = %22, %11
%13 = load i8, i8* %2
%14 = call i64 @is_digit(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %31
16: ; preds = %12
%17 = load i32, i32* %1
%18 = load i32, i32* @LONG_MAX
%19 = icmp sge i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i32, i32* @LONG_MAX
store i32 %21, i32* %1
br label %31
22: ; preds = %16
%23 = load i32, i32* %1
%24 = mul nsw i32 %23, 10
store i32 %24, i32* %1
%25 = load i8, i8* %2
%26 = sext i8 %25 to i32
%27 = sub nsw i32 %26, 48
%28 = load i32, i32* %1
%29 = add nsw i32 %28, %27
store i32 %29, i32* %1
%30 = call signext i8 (...) @getchar()
store i8 %30, i8* %2
br label %12
31: ; preds = %20, %12
br label %32
32: ; preds = %36, %31
%33 = load i8, i8* %2
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 10
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call signext i8 (...) @getchar()
store i8 %37, i8* %2
br label %32
38: ; preds = %32
%39 = load i32, i32* %1
%40 = sext i32 %39 to i64
ret i64 %40
}

LLVM IR (-O2):
@.str = [3 x i8] c"> \00"
@LONG_MAX = global i32 0
define i64 @get_long() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%2 = tail call i64 @is_digit(i8 signext 0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %8, %0
%5 = phi i8 [ 0, %0 ], [ %9, %8 ]
%6 = tail call i64 @is_digit(i8 signext %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %25, label %12
8: ; preds = %0, %8
%9 = tail call signext i8 (...) @getchar()
%10 = tail call i64 @is_digit(i8 signext %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %8, label %4
12: ; preds = %4, %17
%13 = phi i8 [ %22, %17 ], [ %5, %4 ]
%14 = phi i32 [ %21, %17 ], [ 0, %4 ]
%15 = load i32, i32* @LONG_MAX
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = mul nsw i32 %14, 10
%19 = sext i8 %13 to i32
%20 = add i32 %18, -48
%21 = add i32 %20, %19
%22 = tail call signext i8 (...) @getchar()
%23 = tail call i64 @is_digit(i8 signext %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %12
25: ; preds = %17, %12, %4
%26 = phi i8 [ %5, %4 ], [ %13, %12 ], [ %22, %17 ]
%27 = phi i32 [ 0, %4 ], [ %15, %12 ], [ %21, %17 ]
%28 = icmp eq i8 %26, 10
br i1 %28, label %32, label %29
29: ; preds = %25, %29
%30 = tail call signext i8 (...) @getchar()
%31 = icmp eq i8 %30, 10
br i1 %31, label %32, label %29
32: ; preds = %29, %25
%33 = sext i32 %27 to i64
ret i64 %33
}