#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*/ getchar();
int log(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void nine() {
  int decimal, length, i;
  printf("enter number (int): ");
  scanf("%d", &decimal);
  length = (int)(1 + log(decimal) / log(2));
  char binary[length];
  for (i = 0; decimal > 0; ++i, decimal /= 2)
    binary[i] = '0' + decimal % 2;
  printf("\ngenerated binary number: ");
  for (--i; i >= 0; --i)
    printf("%c", binary[i]);
  printf("\n");
  getchar();
  printf("\nreturning to menu. press Enter...");
  getchar();
}


x86 assembly (clang, -O0):
<nine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb8(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x4(%rbp),%edi
call   1060 <log@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x2,%edi
call   1060 <log@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    11f5 <nine+0xb5>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%rax
add    $0x30,%edx
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    11b6 <nine+0x76>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     123e <nine+0xfe>
mov    -0x28(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    120c <nine+0xcc>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nine>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea6(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <log@plt>
mov    %eax,%ebx
mov    $0x2,%edi
call   1070 <log@plt>
mov    %eax,%ecx
mov    %rsp,%r14
mov    %ebx,%eax
cltd
idiv   %ecx
add    $0x1,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x1c(%rbp),%eax
test   %eax,%eax
jle    1217 <nine+0xc7>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%ecx
mov    %ecx,%edx
and    $0x1,%dl
or     $0x30,%dl
mov    %dl,(%r15,%rbx,1)
add    $0x1,%rbx
shr    %eax
cmp    $0x1,%ecx
ja     11c0 <nine+0x70>
mov    %eax,-0x1c(%rbp)
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
jle    1225 <nine+0xd5>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl -0x2(%r15,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1200 <nine+0xb0>
jmp    1225 <nine+0xd5>
lea    0xdfa(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
lea    0xdf6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %r14,%rsp
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"enter number (int): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"\0Agenerated binary number: \00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [35 x i8] c"\0Areturning to menu. press Enter...\00"
define void @nine() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = call i32 @log(i32 %8)
%10 = call i32 @log(i32 2)
%11 = sdiv i32 %9, %10
%12 = add nsw i32 1, %11
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %4
%16 = alloca i8, i64 %14
store i64 %14, i64* %5
store i32 0, i32* %3
br label %17
17: ; preds = %28, %0
%18 = load i32, i32* %1
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %17
%21 = load i32, i32* %1
%22 = srem i32 %21, 2
%23 = add nsw i32 48, %22
%24 = trunc i32 %23 to i8
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %16, i64 %26
store i8 %24, i8* %27
br label %28
28: ; preds = %20
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
%31 = load i32, i32* %1
%32 = sdiv i32 %31, 2
store i32 %32, i32* %1
br label %17
33: ; preds = %17
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32, i32* %3
%36 = add nsw i32 %35, -1
store i32 %36, i32* %3
br label %37
37: ; preds = %47, %33
%38 = load i32, i32* %3
%39 = icmp sge i32 %38, 0
br i1 %39, label %40, label %50
40: ; preds = %37
%41 = load i32, i32* %3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %16, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %40
%48 = load i32, i32* %3
%49 = add nsw i32 %48, -1
store i32 %49, i32* %3
br label %37
50: ; preds = %37
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%52 = call i32 (...) @getchar()
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%54 = call i32 (...) @getchar()
%55 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"enter number (int): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"\0Agenerated binary number: \00"
@.str.5 = [35 x i8] c"\0Areturning to menu. press Enter...\00"
define void @nine() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = call i32 @log(i32 %5)
%7 = call i32 @log(i32 2)
%8 = sdiv i32 %6, %7
%9 = add nsw i32 %8, 1
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = load i32, i32* %1
%14 = icmp sgt i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %41
17: ; preds = %0, %17
%18 = phi i64 [ %24, %17 ], [ 0, %0 ]
%19 = phi i32 [ %25, %17 ], [ %13, %0 ]
%20 = trunc i32 %19 to i8
%21 = and i8 %20, 1
%22 = or i8 %21, 48
%23 = getelementptr inbounds i8, i8* %12, i64 %18
store i8 %22, i8* %23
%24 = add nuw nsw i64 %18, 1
%25 = lshr i32 %19, 1
%26 = icmp ult i32 %19, 2
br i1 %26, label %27, label %17
27: ; preds = %17
%28 = trunc i64 %24 to i32
store i32 %25, i32* %1
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp sgt i32 %28, 0
br i1 %30, label %31, label %41
31: ; preds = %27
%32 = and i64 %24, 4294967295
br label %33
33: ; preds = %31, %33
%34 = phi i64 [ %32, %31 ], [ %35, %33 ]
%35 = add nsw i64 %34, -1
%36 = getelementptr inbounds i8, i8* %12, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = call i32 @putchar(i32 %38)
%40 = icmp ugt i64 %34, 1
br i1 %40, label %33, label %41
41: ; preds = %33, %15, %27
%42 = call i32 @putchar(i32 10)
%43 = call i32 (...) @getchar()
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%45 = call i32 (...) @getchar()
ret void
}