#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 */
unsigned int setIByte(unsigned int, int);
unsigned int DecToBin(int i) {
  int j;
  int cpt = 1;
  unsigned int res = 0x0;
  while (i > 0) {
    j = i % 2;
    if (j == 1) {
      res = setIByte(res, cpt);
    }
    i = i / 2;
    cpt++;
  }
  return res;
}


x86 assembly (clang, -O0):
<DecToBin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1175 <DecToBin+0x65>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1159 <DecToBin+0x49>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <setIByte@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1129 <DecToBin+0x19>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DecToBin>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
jle    114e <DecToBin+0x3e>
mov    %edi,%ebx
mov    $0x1,%ebp
xor    %eax,%eax
jmp    113e <DecToBin+0x2e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%ecx
shr    %ecx
add    $0x1,%ebp
cmp    $0x1,%ebx
mov    %ecx,%ebx
jbe    1150 <DecToBin+0x40>
test   $0x1,%bl
je     1130 <DecToBin+0x20>
mov    %eax,%edi
mov    %ebp,%esi
call   1030 <setIByte@plt>
jmp    1130 <DecToBin+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @DecToBin(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %18, %1
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %6
%10 = load i32, i32* %2
%11 = srem i32 %10, 2
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* %5
%16 = load i32, i32* %4
%17 = call i32 @setIByte(i32 %15, i32 %16)
store i32 %17, i32* %5
br label %18
18: ; preds = %14, %9
%19 = load i32, i32* %2
%20 = sdiv i32 %19, 2
store i32 %20, i32* %2
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %6
23: ; preds = %6
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
define i32 @DecToBin(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %3, label %16
3: ; preds = %1, %11
%4 = phi i32 [ %12, %11 ], [ 0, %1 ]
%5 = phi i32 [ %14, %11 ], [ 1, %1 ]
%6 = phi i32 [ %13, %11 ], [ %0, %1 ]
%7 = and i32 %6, 1
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = tail call i32 @setIByte(i32 %4, i32 %5)
br label %11
11: ; preds = %9, %3
%12 = phi i32 [ %10, %9 ], [ %4, %3 ]
%13 = lshr i32 %6, 1
%14 = add nuw nsw i32 %5, 1
%15 = icmp ult i32 %6, 2
br i1 %15, label %16, label %3
16: ; preds = %11, %1
%17 = phi i32 [ 0, %1 ], [ %12, %11 ]
ret i32 %17
}