#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 atoi(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printbitssimple(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int guess_num_from_binary(void) {
  int random_num;
  char ans[8];
  srand(time(NULL));
  random_num = rand() % 100 + 1;
  puts("Here is the number:");
  printbitssimple(random_num);
  puts("\nEnter your answer");
  fgets(ans, 6, stdin);
  putchar('\n');
  printf("you typed: %s \n", ans);
  if (atoi(ans) == random_num) {
    return 0;
  } else {
    return random_num;
  }
}


x86 assembly (clang, -O0):
<guess_num_from_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    $0x0,%al
call   10b0 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
lea    0xe3c(%rip),%rdi
call   1040 <puts@plt>
mov    -0x8(%rbp),%edi
call   1050 <printbitssimple@plt>
lea    0xe3c(%rip),%rdi
call   1040 <puts@plt>
lea    -0x10(%rbp),%rdi
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
mov    $0x6,%esi
call   1080 <fgets@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    -0x10(%rbp),%rsi
lea    0xe1e(%rip),%rdi
call   1060 <printf@plt>
lea    -0x10(%rbp),%rdi
call   10a0 <atoi@plt>
cmp    -0x8(%rbp),%eax
jne    122c <guess_num_from_binary+0x9c>
movl   $0x0,-0x4(%rbp)
jmp    1232 <guess_num_from_binary+0xa2>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guess_num_from_binary>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %r15d,%r15d
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
xor    %eax,%eax
call   10b0 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%ebx
add    $0x1,%ebx
lea    0xe27(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1050 <printbitssimple@plt>
lea    0xe28(%rip),%rdi
call   1040 <puts@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x6,%esi
call   1080 <fgets@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe0a(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
mov    %r14,%rdi
call   10a0 <atoi@plt>
cmp    %ebx,%eax
cmove  %r15d,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Here is the number:\00"
@.str.1 = [19 x i8] c"\0AEnter your answer\00"
@stdin = global i32 0
@.str.2 = [16 x i8] c"you typed: %s \0A\00"
define i32 @guess_num_from_binary() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [8 x i8]
%4 = call i32 @time(i32* null)
%5 = call i32 @srand(i32 %4)
%6 = call i32 (...) @rand()
%7 = srem i32 %6, 100
%8 = add nsw i32 %7, 1
store i32 %8, i32* %2
%9 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %2
%11 = call i32 @printbitssimple(i32 %10)
%12 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %13, i32 6, i32 %14)
%16 = call i32 @putchar(i8 signext 10)
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%18 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%20 = call i32 @atoi(i8* %19)
%21 = load i32, i32* %2
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %0
store i32 0, i32* %1
br label %26
24: ; preds = %0
%25 = load i32, i32* %2
store i32 %25, i32* %1
br label %26
26: ; preds = %24, %23
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [20 x i8] c"Here is the number:\00"
@.str.1 = [19 x i8] c"\0AEnter your answer\00"
@stdin = global i32 0
@.str.2 = [16 x i8] c"you typed: %s \0A\00"
define i32 @guess_num_from_binary() {
%1 = alloca [8 x i8]
%2 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 100
%7 = add nsw i32 %6, 1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @printbitssimple(i32 %7)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %2, i32 6, i32 %11)
%13 = call i32 @putchar(i8 signext 10)
%14 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%15 = call i32 @atoi(i8* %2)
%16 = icmp eq i32 %15, %7
%17 = select i1 %16, i32 0, i32 %7
ret i32 %17
}