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


x86 assembly (clang, -O0):
<guess_binary_from_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
mov    $0x0,%al
call   10b0 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe43(%rip),%rdi
call   1050 <puts@plt>
lea    -0x20(%rbp),%rdi
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1090 <fgets@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1070 <createbitshape@plt>
lea    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    123a <guess_binary_from_num+0xaa>
lea    0xe02(%rip),%rdi
call   1050 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    126f <guess_binary_from_num+0xdf>
lea    -0x20(%rbp),%rsi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x28(%rbp),%rsi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guess_binary_from_num>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
xor    %r14d,%r14d
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1080 <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),%ebp
add    $0x1,%ebp
lea    0xe26(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe2e(%rip),%rdi
call   1050 <puts@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x14,%esi
call   1090 <fgets@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x8(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <createbitshape@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     1269 <guess_binary_from_num+0xd9>
lea    0xdfe(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdfb(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    127b <guess_binary_from_num+0xeb>
lea    0xdbb(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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