#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 *, char *);
void int2bin(int num) {
  char str[9] = {0};
  int i;
  for (i = 7; i >= 0; i--) {
    str[i] = (num & 1) ? '1' : '0';
    num >>= 1;
  }
  printf("%s\n", str);
}


x86 assembly (clang, -O0):
<int2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0xd(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1040 <memset@plt>
movl   $0x7,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1183 <int2bin+0x63>
mov    -0x4(%rbp),%edx
and    $0x1,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0xd(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1142 <int2bin+0x22>
lea    -0xd(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int2bin>:
sub    $0x18,%rsp
movb   $0x0,0x17(%rsp)
mov    %edi,%eax
and    $0x1,%al
or     $0x30,%al
mov    %al,0x16(%rsp)
mov    %edi,%eax
shr    %al
and    $0x1,%al
or     $0x30,%al
mov    %al,0x15(%rsp)
mov    %edi,%eax
shr    $0x2,%al
and    $0x1,%al
or     $0x30,%al
mov    %al,0x14(%rsp)
mov    %edi,%eax
shr    $0x3,%al
and    $0x1,%al
or     $0x30,%al
mov    %al,0x13(%rsp)
mov    %edi,%eax
shr    $0x4,%al
and    $0x1,%al
or     $0x30,%al
mov    %al,0x12(%rsp)
mov    %edi,%eax
shr    $0x5,%al
and    $0x1,%al
or     $0x30,%al
mov    %al,0x11(%rsp)
mov    %edi,%eax
shr    $0x6,%al
and    $0x1,%al
or     $0x30,%al
mov    %al,0x10(%rsp)
shr    $0x7,%dil
or     $0x30,%dil
mov    %dil,0xf(%rsp)
lea    0xe7c(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1030 <printf@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define void @int2bin(i32 %0) {
%2 = alloca i32
%3 = alloca [9 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = bitcast [9 x i8]* %3 to i8*
store i32 7, i32* %4
br label %6
6: ; preds = %21, %1
%7 = load i32, i32* %4
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = load i32, i32* %2
%11 = and i32 %10, 1
%12 = icmp ne i32 %11, 0
%13 = zext i1 %12 to i64
%14 = select i1 %12, i32 49, i32 48
%15 = trunc i32 %14 to i8
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 %17
store i8 %15, i8* %18
%19 = load i32, i32* %2
%20 = ashr i32 %19, 1
store i32 %20, i32* %2
br label %21
21: ; preds = %9
%22 = load i32, i32* %4
%23 = add nsw i32 %22, -1
store i32 %23, i32* %4
br label %6
24: ; preds = %6
%25 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %25)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define void @int2bin(i32 %0) {
%2 = alloca [9 x i8]
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 8
store i8 0, i8* %4
%5 = trunc i32 %0 to i8
%6 = and i8 %5, 1
%7 = or i8 %6, 48
%8 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 7
store i8 %7, i8* %8
%9 = trunc i32 %0 to i8
%10 = lshr i8 %9, 1
%11 = and i8 %10, 1
%12 = or i8 %11, 48
%13 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 6
store i8 %12, i8* %13
%14 = trunc i32 %0 to i8
%15 = lshr i8 %14, 2
%16 = and i8 %15, 1
%17 = or i8 %16, 48
%18 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 5
store i8 %17, i8* %18
%19 = trunc i32 %0 to i8
%20 = lshr i8 %19, 3
%21 = and i8 %20, 1
%22 = or i8 %21, 48
%23 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 4
store i8 %22, i8* %23
%24 = trunc i32 %0 to i8
%25 = lshr i8 %24, 4
%26 = and i8 %25, 1
%27 = or i8 %26, 48
%28 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 3
store i8 %27, i8* %28
%29 = trunc i32 %0 to i8
%30 = lshr i8 %29, 5
%31 = and i8 %30, 1
%32 = or i8 %31, 48
%33 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 2
store i8 %32, i8* %33
%34 = trunc i32 %0 to i8
%35 = lshr i8 %34, 6
%36 = and i8 %35, 1
%37 = or i8 %36, 48
%38 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 1
store i8 %37, i8* %38
%39 = trunc i32 %0 to i8
%40 = lshr i8 %39, 7
%41 = or i8 %40, 48
store i8 %41, i8* %3
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %3)
ret void
}