#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 /*<<< orphan*/ chop(char *);
scalar_t__ errno;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
scalar_t__ strtol(char *, char **, int);
long readl(char *prompt) {
  char str[20];
  long l;
  char *ep;
  while (true) {
    printf("%s: ", prompt);
    fgets(str, 20, stdin);
    chop(str);
    errno = 0;
    l = (int)strtol(str, &ep, 10);
    if (strlen(str) < 1 || errno || *ep) {
      printf("Sorry, '%s' is not a valid integer. Try again.\n", str);
    } else {
      return l;
    }
  }
}


x86 assembly (clang, -O0):
<readl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1060 <fgets@plt>
lea    -0x20(%rbp),%rdi
call   1050 <chop@plt>
mov    0x2e45(%rip),%rax
movq   $0x0,(%rax)
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
cltq
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jl     11e5 <readl+0x95>
mov    0x2e0d(%rip),%rax
cmpq   $0x0,(%rax)
jne    11e5 <readl+0x95>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11fa <readl+0xaa>
lea    -0x20(%rbp),%rsi
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
jmp    1204 <readl+0xb4>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret
jmp    115c <readl+0xc>

x86 assembly (clang, -O2):
<readl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r15
lea    0x10(%rsp),%rbx
mov    0x2e6b(%rip),%r14
lea    0x8(%rsp),%r12
lea    0xe8c(%rip),%r13
jmp    118b <readl+0x3b>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xe6e(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1050 <chop@plt>
movq   $0x0,(%r14)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1180 <readl+0x30>
cmpq   $0x0,(%r14)
jne    1180 <readl+0x30>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    1180 <readl+0x30>
movslq %ebp,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s: \00"
@stdin = global i32 0
@errno = global i64 0
@.str.1 = [48 x i8] c"Sorry, '%s' is not a valid integer. Try again.\0A\00"
define i64 @readl(i8* %0) {
%2 = alloca i8*
%3 = alloca [20 x i8]
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %2
br label %6
6: ; preds = %1, %34
%7 = load i8*, i8** %2
%8 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %9, i32 20, i32 %10)
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%13 = call i32 @chop(i8* %12)
store i64 0, i64* @errno
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%15 = call i64 @strtol(i8* %14, i8** %5, i32 10)
%16 = trunc i64 %15 to i32
%17 = sext i32 %16 to i64
store i64 %17, i64* %4
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = icmp slt i32 %19, 1
br i1 %20, label %29, label %21
21: ; preds = %6
%22 = load i64, i64* @errno
%23 = icmp ne i64 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %21
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24, %21, %6
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%31 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %30)
br label %34
32: ; preds = %24
%33 = load i64, i64* %4
ret i64 %33
34: ; preds = %29
br label %6
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s: \00"
@stdin = global i32 0
@errno = global i64 0
@.str.1 = [48 x i8] c"Sorry, '%s' is not a valid integer. Try again.\0A\00"
define i64 @readl(i8* %0) {
%2 = alloca [20 x i8]
%3 = alloca i8*
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = bitcast i8** %3 to i8*
br label %6
6: ; preds = %21, %1
%7 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %4, i32 20, i32 %8)
%10 = call i32 @chop(i8* %4)
store i64 0, i64* @errno
%11 = call i64 @strtol(i8* %4, i8** %3, i32 10)
%12 = call i32 @strlen(i8* %4)
%13 = icmp slt i32 %12, 1
%14 = load i64, i64* @errno
%15 = icmp ne i64 %14, 0
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %21, label %17
17: ; preds = %6
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %17, %6
%22 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %6
23: ; preds = %17
%24 = shl i64 %11, 32
%25 = ashr exact i64 %24, 32
ret i64 %25
}