#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 */
typedef int /*<<< orphan*/ num;

/* Variables and functions */
int /*<<< orphan*/ putchar(char);
void print_binary(int num) {
  unsigned int i;
  i = 1 << (sizeof(num) * 8 - 1);
  int started = 0;
  while (i > 0) {
    if (num & i) {
      putchar('1');
      started = 1;
    } else if (started)
      putchar('0');
    i >>= 1;
  }
  putchar('\n');
}


x86 assembly (clang, -O0):
<print_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x80000000,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jbe    117f <print_binary+0x6f>
mov    -0x4(%rbp),%eax
and    -0x8(%rbp),%eax
cmp    $0x0,%eax
je     1158 <print_binary+0x48>
mov    $0x31,%edi
call   1030 <putchar@plt>
movl   $0x1,-0xc(%rbp)
jmp    1171 <print_binary+0x61>
cmpl   $0x0,-0xc(%rbp)
je     116c <print_binary+0x5c>
mov    $0x30,%edi
call   1030 <putchar@plt>
jmp    1171 <print_binary+0x61>
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <print_binary+0x19>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_binary>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x80000000,%ebp
xor    %eax,%eax
jmp    1138 <print_binary+0x28>
xchg   %ax,%ax
movzbl %cl,%edi
call   1030 <putchar@plt>
mov    $0x1,%eax
mov    %ebp,%ecx
shr    %ecx
cmp    $0x1,%ebp
mov    %ecx,%ebp
jbe    1148 <print_binary+0x38>
mov    $0x31,%cl
test   %ebx,%ebp
jne    1120 <print_binary+0x10>
mov    $0x30,%cl
test   %eax,%eax
jne    1120 <print_binary+0x10>
xor    %eax,%eax
jmp    112d <print_binary+0x1d>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
define void @print_binary(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 -2147483648, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %21, %1
%6 = load i32, i32* %3
%7 = icmp ugt i32 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %5
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = and i32 %9, %10
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @putchar(i8 signext 49)
store i32 1, i32* %4
br label %21
15: ; preds = %8
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @putchar(i8 signext 48)
br label %20
20: ; preds = %18, %15
br label %21
21: ; preds = %20, %13
%22 = load i32, i32* %3
%23 = lshr i32 %22, 1
store i32 %23, i32* %3
br label %5
24: ; preds = %5
%25 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
define void @print_binary(i32 %0) {
br label %2
2: ; preds = %1, %12
%3 = phi i32 [ 0, %1 ], [ %13, %12 ]
%4 = phi i32 [ -2147483648, %1 ], [ %14, %12 ]
%5 = and i32 %4, %0
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = icmp eq i32 %3, 0
br i1 %8, label %12, label %9
9: ; preds = %7, %2
%10 = phi i8 [ 49, %2 ], [ 48, %7 ]
%11 = tail call i32 @putchar(i8 signext %10)
br label %12
12: ; preds = %9, %7
%13 = phi i32 [ 0, %7 ], [ 1, %9 ]
%14 = lshr i32 %4, 1
%15 = icmp ult i32 %4, 2
br i1 %15, label %16, label %2
16: ; preds = %12
%17 = tail call i32 @putchar(i8 signext 10)
ret void
}