#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*/ countup(long *, int);
int /*<<< orphan*/ getstryng(char *);
int /*<<< orphan*/ printf(char *, char const *);
int sscanf(char *, char *, long *);
long readlong(const char *prompt) {
  long res, loopcount;
  char string[100];
  loopcount = 0;
  do {
    printf("%s", prompt);
    getstryng(string);
    if (sscanf(string, "%ld", &res) == 1)
      break;
    countup(&loopcount, 10);
  } while (1);
  return res;
}


x86 assembly (clang, -O0):
<readlong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
lea    -0x80(%rbp),%rdi
call   1040 <getstryng@plt>
lea    -0x80(%rbp),%rdi
lea    0xe88(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <readlong+0x52>
jmp    11af <readlong+0x6f>
lea    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1060 <countup@plt>
mov    $0x1,%al
test   $0x1,%al
jne    1157 <readlong+0x17>
jmp    11af <readlong+0x6f>
mov    -0x10(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readlong>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdi,%r12
movq   $0x0,0x8(%rsp)
lea    0xe9f(%rip),%rdi
mov    %r12,%rsi
call   1030 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <getstryng@plt>
lea    0xe86(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     11e3 <readlong+0xa3>
lea    0x8(%rsp),%r14
lea    0xe67(%rip),%r15
lea    0x10(%rsp),%rbx
lea    0xe5e(%rip),%r13
mov    %rsp,%rbp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0xa,%esi
call   1060 <countup@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <getstryng@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11b0 <readlong+0x70>
mov    (%rsp),%rax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"%ld\00"
define i64 @readlong(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca [100 x i8]
store i8* %0, i8** %2
store i64 0, i64* %4
br label %6
6: ; preds = %17, %1
%7 = load i8*, i8** %2
%8 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%10 = call i32 @getstryng(i8* %9)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %6
br label %18
15: ; preds = %6
%16 = call i32 @countup(i64* %4, i32 10)
br label %17
17: ; preds = %15
br i1 true, label %6, label %18
18: ; preds = %17, %14
%19 = load i64, i64* %3
ret i64 %19
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"%ld\00"
define i64 @readlong(i8* %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca [100 x i8]
%5 = bitcast i64* %2 to i8*
%6 = bitcast i64* %3 to i8*
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
store i64 0, i64* %3
%8 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = call i32 @getstryng(i8* %7)
%10 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%11 = icmp eq i32 %10, 1
br i1 %11, label %18, label %12
12: ; preds = %1, %12
%13 = call i32 @countup(i64* %3, i32 10)
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%15 = call i32 @getstryng(i8* %7)
%16 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %12
18: ; preds = %12, %1
%19 = load i64, i64* %2
ret i64 %19
}