#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 *, unsigned long long *);
int main() {
  unsigned long long num;
  unsigned pos = 0;
  char result[512];
  printf("Enter a number: ");
  scanf("%I64u", &num);
  printf("%I64u dec => ", num);
  if (num == 0)
    printf("0");
  for (; num > 0; num /= 2)
    result[pos++] = '0' + num % 2;
  while (pos)
    printf("%c", result[--pos]);
  printf(" bin\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec3(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%rsi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1182 <main+0x62>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1187 <main+0x67>
cmpq   $0x0,-0x10(%rbp)
jbe    11c5 <main+0xa5>
mov    -0x10(%rbp),%rax
and    $0x1,%rax
add    $0x30,%rax
mov    %al,%cl
mov    -0x14(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
mov    %eax,%eax
mov    %cl,-0x220(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1187 <main+0x67>
jmp    11ca <main+0xaa>
cmpl   $0x0,-0x14(%rbp)
je     11fa <main+0xda>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    %eax,%eax
movsbl -0x220(%rbp,%rax,1),%esi
ff
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ca <main+0xaa>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x210,%rsp
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x8(%rsp),%rsi
lea    0xea4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rax
test   %rax,%rax
jne    1198 <main+0x58>
mov    $0x30,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     11e0 <main+0xa0>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %rax,%rcx
mov    %ecx,%edx
and    $0x1,%dl
or     $0x30,%dl
mov    %dl,0x10(%rsp,%rbx,1)
add    $0x1,%rbx
shr    %rax
cmp    $0x2,%rcx
jae    11a0 <main+0x60>
mov    %rax,0x8(%rsp)
test   %ebx,%ebx
je     11e0 <main+0xa0>
cs nopw 0x0(%rax,%rax,1)
nop
movsbl 0xf(%rsp,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
jne    11d0 <main+0x90>
lea    0xe3e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [6 x i8] c"%I64u\00"
@.str.2 = [14 x i8] c"%I64u dec => \00"
@.str.3 = [2 x i8] c"0\00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [6 x i8] c" bin\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca [512 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%7 = load i64, i64* %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i64 %7)
%9 = load i64, i64* %2
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
br label %14
14: ; preds = %26, %13
%15 = load i64, i64* %2
%16 = icmp ugt i64 %15, 0
br i1 %16, label %17, label %29
17: ; preds = %14
%18 = load i64, i64* %2
%19 = urem i64 %18, 2
%20 = add i64 48, %19
%21 = trunc i64 %20 to i8
%22 = load i32, i32* %3
%23 = add i32 %22, 1
store i32 %23, i32* %3
%24 = zext i32 %22 to i64
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %24
store i8 %21, i8* %25
br label %26
26: ; preds = %17
%27 = load i64, i64* %2
%28 = udiv i64 %27, 2
store i64 %28, i64* %2
br label %14
29: ; preds = %14
br label %30
30: ; preds = %33, %29
%31 = load i32, i32* %3
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = load i32, i32* %3
%35 = add i32 %34, -1
store i32 %35, i32* %3
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %39)
br label %30
41: ; preds = %30
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [6 x i8] c"%I64u\00"
@.str.2 = [14 x i8] c"%I64u dec => \00"
@str = [5 x i8] c" bin\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [512 x i8]
%3 = bitcast i64* %1 to i8*
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%7 = load i64, i64* %1
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i64 %7)
%9 = load i64, i64* %1
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = call i32 @putchar(i32 48)
%13 = load i64, i64* %1
%14 = icmp eq i64 %13, 0
br i1 %14, label %40, label %15
15: ; preds = %0, %11
%16 = phi i64 [ %13, %11 ], [ %9, %0 ]
br label %22
17: ; preds = %22
%18 = trunc i64 %28 to i32
store i64 %30, i64* %1
%19 = icmp eq i32 %18, 0
br i1 %19, label %40, label %20
20: ; preds = %17
%21 = and i64 %28, 4294967295
br label %32
22: ; preds = %15, %22
%23 = phi i64 [ %28, %22 ], [ 0, %15 ]
%24 = phi i64 [ %30, %22 ], [ %16, %15 ]
%25 = trunc i64 %24 to i8
%26 = and i8 %25, 1
%27 = or i8 %26, 48
%28 = add nuw nsw i64 %23, 1
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %23
store i8 %27, i8* %29
%30 = lshr i64 %24, 1
%31 = icmp ult i64 %24, 2
br i1 %31, label %17, label %22
32: ; preds = %20, %32
%33 = phi i64 [ %21, %20 ], [ %34, %32 ]
%34 = add nsw i64 %33, -1
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = call i32 @putchar(i32 %37)
%39 = icmp eq i64 %34, 0
br i1 %39, label %40, label %32
40: ; preds = %32, %11, %17
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
ret i32 0
}