#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
uintptr_t strtol(char *, int /*<<< orphan*/ *, int);
void stub1();
int main(int argc, char **argv) {
  uintptr_t val;
  char buf[32] = "";
  setbuf(stdout, NULL);
  printf("Welcome to the number guessing game!\n");
  printf("I'm thinking of a number. Can you guess it?\n");
  printf("Guess right and you get a shell!\n");
  printf("Enter your number: ");
  scanf("%32s", buf);
  val = strtol(buf, NULL, 10);
  printf("You entered %d. Let's see if it was right...\n", val);
  val >>= 4;
  ((void (*)(void))val)();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <setbuf@plt>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xec5(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
shr    $0x4,%rax
mov    %rax,-0x18(%rbp)
call   *-0x18(%rbp)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <setbuf@plt>
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
lea    0xf08(%rip),%rdi
call   1030 <puts@plt>
lea    0xe64(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe6a(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,%rbx
lea    0xe4b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
shr    $0x4,%rbx
call   *%rbx
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [38 x i8] c"Welcome to the number guessing game!\0A\00"
@.str.1 = [45 x i8] c"I'm thinking of a number. Can you guess it?\0A\00"
@.str.2 = [34 x i8] c"Guess right and you get a shell!\0A\00"
@.str.3 = [20 x i8] c"Enter your number: \00"
@.str.4 = [5 x i8] c"%32s\00"
@.str.5 = [46 x i8] c"You entered %d. Let's see if it was right...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i64
%6 = alloca [32 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = bitcast [32 x i8]* %6 to i8*
%8 = load i32, i32* @stdout
%9 = call i32 @setbuf(i32 %8, i32* null)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%15 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%17 = call i64 @strtol(i8* %16, i32* null, i32 10)
store i64 %17, i64* %5
%18 = load i64, i64* %5
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i64 %18)
%20 = load i64, i64* %5
%21 = lshr i64 %20, 4
store i64 %21, i64* %5
%22 = load i64, i64* %5
%23 = inttoptr i64 %22 to void ()*
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str.3 = [20 x i8] c"Enter your number: \00"
@.str.4 = [5 x i8] c"%32s\00"
@.str.5 = [46 x i8] c"You entered %d. Let's see if it was right...\0A\00"
@str = [37 x i8] c"Welcome to the number guessing game!\00"
@str.6 = [44 x i8] c"I'm thinking of a number. Can you guess it?\00"
@str.7 = [33 x i8] c"Guess right and you get a shell!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @stdout
%6 = tail call i32 @setbuf(i32 %5, i32* null)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.6, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.7, i64 0, i64 0))
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%12 = call i64 @strtol(i8* nocapture %4, i32* null, i32 10)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i64 %12)
%14 = lshr i64 %12, 4
%15 = inttoptr i64 %14 to void ()*
ret i32 0
}