#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*/ free(char *);
char *get_string();
int /*<<< orphan*/ printf(char *, char *);
long strtol(char *, char **, int);
int get_long(long *x) {
  char *aux = get_string();
  char *aux2;
  long out;
  if (aux == NULL) {
    return 1;
  }
  out = strtol(aux, &aux2, 10);
  if (aux2 == aux) {
    printf("\tInvalid. Expected number, got '%s'. Please input number: ", aux);
    free(aux);
    return get_long(x);
  } else {
    free(aux);
  }
  *x = out;
  return 0;
}


x86 assembly (clang, -O0):
<get_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <get_string@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117e <get_long+0x2e>
movl   $0x1,-0x4(%rbp)
jmp    11e7 <get_long+0x97>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11cc <get_long+0x7c>
mov    -0x18(%rbp),%rsi
lea    0xe53(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <get_long@plt>
mov    %eax,-0x4(%rbp)
jmp    11e7 <get_long+0x97>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_long>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <get_string@plt>
test   %rax,%rax
je     1196 <get_long+0x46>
mov    %rax,%rbx
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1070 <strtol@plt>
cmp    %rbx,0x8(%rsp)
je     11a5 <get_long+0x55>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,(%r14)
xor    %eax,%eax
jmp    119b <get_long+0x4b>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe54(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <get_long@plt>

LLVM IR (-O0):
@.str = [59 x i8] c"\09Invalid. Expected number, got '%s'. Please input number: \00"
define i32 @get_long(i64* %0) {
%2 = alloca i32
%3 = alloca i64*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i64* %0, i64** %3
%7 = call i8* (...) @get_string()
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 1, i32* %2
br label %30
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = call i64 @strtol(i8* %12, i8** %5, i32 10)
store i64 %13, i64* %6
%14 = load i8*, i8** %5
%15 = load i8*, i8** %4
%16 = icmp eq i8* %14, %15
br i1 %16, label %17, label %24
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
%22 = load i64*, i64** %3
%23 = call i32 @get_long(i64* %22)
store i32 %23, i32* %2
br label %30
24: ; preds = %11
%25 = load i8*, i8** %4
%26 = call i32 @free(i8* %25)
br label %27
27: ; preds = %24
%28 = load i64, i64* %6
%29 = load i64*, i64** %3
store i64 %28, i64* %29
store i32 0, i32* %2
br label %30
30: ; preds = %27, %17, %10
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [59 x i8] c"\09Invalid. Expected number, got '%s'. Please input number: \00"
define i32 @get_long(i64* nocapture writeonly %0) {
%2 = alloca i8*
%3 = tail call i8* (...) @get_string()
%4 = bitcast i8** %2 to i8*
%5 = icmp eq i8* %3, null
br i1 %5, label %16, label %6
6: ; preds = %1
%7 = call i64 @strtol(i8* %3, i8** %2, i32 10)
%8 = load i8*, i8** %2
%9 = icmp eq i8* %8, %3
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = tail call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %3)
%12 = tail call i32 @free(i8* %3)
%13 = tail call i32 @get_long(i64* %0)
br label %16
14: ; preds = %6
%15 = tail call i32 @free(i8* %3)
store i64 %7, i64* %0
br label %16
16: ; preds = %1, %14, %10
%17 = phi i32 [ %13, %10 ], [ 0, %14 ], [ 1, %1 ]
ret i32 %17
}