#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 *, ...);
void dec_bin(int x) {
  int tab[8];
  int i = 0;
  while (x != 0) {
    tab[i] = x % 2;
    x = x / 2;
    i++;
  }
  while (i > 0) {
    i--;
    printf("%i", tab[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dec_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     115b <dec_bin+0x4b>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq -0x34(%rbp),%rax
mov    %edx,-0x30(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1122 <dec_bin+0x12>
jmp    1160 <dec_bin+0x50>
cmpl   $0x0,-0x34(%rbp)
jle    118e <dec_bin+0x7e>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1160 <dec_bin+0x50>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec_bin>:
push   %r14
push   %rbx
sub    $0x28,%rsp
test   %edi,%edi
je     118a <dec_bin+0x6a>
xor    %eax,%eax
mov    %edi,%ecx
nop
shr    $0x1f,%ecx
add    %edi,%ecx
mov    %ecx,%edx
and    $0xfffffffe,%edx
mov    %edi,%esi
sub    %edx,%esi
mov    %esi,(%rsp,%rax,4)
sar    %ecx
add    $0x1,%rax
add    $0x1,%edi
cmp    $0x3,%edi
mov    %ecx,%edi
jae    1130 <dec_bin+0x10>
test   %eax,%eax
jle    118a <dec_bin+0x6a>
mov    %eax,%ebx
add    $0x1,%rbx
lea    0xe9e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    -0x2(%rbx),%eax
mov    (%rsp,%rax,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1170 <dec_bin+0x50>
mov    $0xa,%edi
add    $0x28,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @dec_bin(i32 %0) {
%2 = alloca i32
%3 = alloca [8 x i32]
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %5
5: ; preds = %8, %1
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = load i32, i32* %2
%10 = srem i32 %9, 2
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 %12
store i32 %10, i32* %13
%14 = load i32, i32* %2
%15 = sdiv i32 %14, 2
store i32 %15, i32* %2
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %5
18: ; preds = %5
br label %19
19: ; preds = %22, %18
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = load i32, i32* %4
%24 = add nsw i32 %23, -1
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %28)
br label %19
30: ; preds = %19
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
define void @dec_bin(i32 %0) {
%2 = alloca [8 x i32]
%3 = bitcast [8 x i32]* %2 to i8*
%4 = icmp eq i32 %0, 0
br i1 %4, label %27, label %10
5: ; preds = %10
%6 = trunc i64 %16 to i32
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %5
%9 = and i64 %16, 4294967295
br label %19
10: ; preds = %1, %10
%11 = phi i64 [ %16, %10 ], [ 0, %1 ]
%12 = phi i32 [ %15, %10 ], [ %0, %1 ]
%13 = srem i32 %12, 2
%14 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %11
store i32 %13, i32* %14
%15 = sdiv i32 %12, 2
%16 = add nuw i64 %11, 1
%17 = add i32 %12, 1
%18 = icmp ult i32 %17, 3
br i1 %18, label %5, label %10
19: ; preds = %8, %19
%20 = phi i64 [ %9, %8 ], [ %21, %19 ]
%21 = add nsw i64 %20, -1
%22 = and i64 %21, 4294967295
%23 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = icmp ugt i64 %20, 1
br i1 %26, label %19, label %27
27: ; preds = %19, %1, %5
%28 = tail call i32 @putchar(i32 10)
ret void
}