#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*/ str;

/* Variables and functions */
int CHAR_BIT;
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int, char *);
void print_integer_in_binary(int n) {
  const int int_bit_count = sizeof(int) * CHAR_BIT;
  unsigned int un = n;
  int sign_bit = 0;
  int i = int_bit_count;
  char str[int_bit_count + 1];
  memset(str, 0, sizeof(str));
  str[i--] = '\0';
  if (n == 0)
    str[i--] = '0';
  else {
    un &= (((unsigned int)1 << (int_bit_count - 1)) - 1);
    sign_bit = ((int)un == n) ? 0 : 1;
    while (un) {
      str[i--] = '0' + (un & 1);
      un >>= 1;
    }
    if (sign_bit) {
      str[0] = '1';
      i = -1;
    }
  }
  i++;
  printf("%d in Binary is '%s'\n", n, &str[i]);
}


x86 assembly (clang, -O0):
<print_integer_in_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2eae(%rip),%rax
mov    (%rax),%eax
shl    $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x30(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x4(%rbp)
jne    11ba <print_integer_in_binary+0x9a>
mov    -0x30(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
movb   $0x30,(%rax,%rcx,1)
jmp    123a <print_integer_in_binary+0x11a>
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
sub    $0x1,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edx
mov    -0x4(%rbp),%esi
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     121d <print_integer_in_binary+0xfd>
mov    -0x30(%rbp),%rax
mov    -0xc(%rbp),%ecx
and    $0x1,%ecx
add    $0x30,%ecx
mov    %cl,%dl
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0xffffffff,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e5 <print_integer_in_binary+0xc5>
cmpl   $0x0,-0x10(%rbp)
je     1235 <print_integer_in_binary+0x115>
mov    -0x30(%rbp),%rax
movb   $0x31,(%rax)
movl   $0xffffffff,-0x14(%rbp)
jmp    123a <print_integer_in_binary+0x11a>
mov    -0x30(%rbp),%rdx
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%esi
movslq -0x14(%rbp),%rax
add    %rax,%rdx
lea    0xda8(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_integer_in_binary>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    0x2eac(%rip),%rax
mov    (%rax),%eax
lea    0x1(,%rax,4),%edx
mov    %eax,%ebx
shl    $0x2,%ebx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
movslq %ebx,%rcx
movb   $0x0,(%rcx,%r15,1)
add    $0xffffffffffffffff,%rcx
test   %r14d,%r14d
je     11ba <print_integer_in_binary+0x9a>
mov    $0xffffffff,%eax
shl    %cl,%eax
not    %eax
mov    %eax,%edx
and    %r14d,%edx
je     11aa <print_integer_in_binary+0x8a>
add    $0xfffffffc,%ebx
or     $0x3,%ebx
movslq %ebx,%rsi
add    %r15,%rsi
mov    %ebx,%ecx
mov    %edx,%edi
xchg   %ax,%ax
mov    %edx,%ebx
and    $0x1,%bl
or     $0x30,%bl
mov    %bl,(%rsi)
shr    %edi
add    $0xffffffffffffffff,%rsi
add    $0xffffffff,%ecx
cmp    $0x1,%edx
mov    %edi,%edx
ja     1190 <print_integer_in_binary+0x70>
cmp    %r14d,%eax
jae    11c4 <print_integer_in_binary+0xa4>
movb   $0x31,(%r15)
mov    $0xffffffff,%ecx
jmp    11c4 <print_integer_in_binary+0xa4>
add    $0xfffffffe,%ebx
movb   $0x30,(%r15,%rcx,1)
mov    %ebx,%ecx
movslq %ecx,%rax
lea    (%rax,%r15,1),%rdx
add    $0x1,%rdx
lea    0xe2a(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
@.str = [22 x i8] c"%d in Binary is '%s'\0A\00"
define void @print_integer_in_binary(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i32 %0, i32* %2
%9 = load i32, i32* @CHAR_BIT
%10 = sext i32 %9 to i64
%11 = mul i64 4, %10
%12 = trunc i64 %11 to i32
store i32 %12, i32* %3
%13 = load i32, i32* %2
store i32 %13, i32* %4
store i32 0, i32* %5
%14 = load i32, i32* %3
store i32 %14, i32* %6
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %7
%19 = alloca i8, i64 %17
store i64 %17, i64* %8
%20 = trunc i64 %17 to i32
%21 = call i32 @memset(i8* %19, i32 0, i32 %20)
%22 = load i32, i32* %6
%23 = add nsw i32 %22, -1
store i32 %23, i32* %6
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %19, i64 %24
store i8 0, i8* %25
%26 = load i32, i32* %2
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %1
%29 = load i32, i32* %6
%30 = add nsw i32 %29, -1
store i32 %30, i32* %6
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %19, i64 %31
store i8 48, i8* %32
br label %65
33: ; preds = %1
%34 = load i32, i32* %3
%35 = sub nsw i32 %34, 1
%36 = shl i32 1, %35
%37 = sub i32 %36, 1
%38 = load i32, i32* %4
%39 = and i32 %38, %37
store i32 %39, i32* %4
%40 = load i32, i32* %4
%41 = load i32, i32* %2
%42 = icmp eq i32 %40, %41
%43 = zext i1 %42 to i64
%44 = select i1 %42, i32 0, i32 1
store i32 %44, i32* %5
br label %45
45: ; preds = %48, %33
%46 = load i32, i32* %4
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %59
48: ; preds = %45
%49 = load i32, i32* %4
%50 = and i32 %49, 1
%51 = add i32 48, %50
%52 = trunc i32 %51 to i8
%53 = load i32, i32* %6
%54 = add nsw i32 %53, -1
store i32 %54, i32* %6
%55 = sext i32 %53 to i64
%56 = getelementptr inbounds i8, i8* %19, i64 %55
store i8 %52, i8* %56
%57 = load i32, i32* %4
%58 = lshr i32 %57, 1
store i32 %58, i32* %4
br label %45
59: ; preds = %45
%60 = load i32, i32* %5
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = getelementptr inbounds i8, i8* %19, i64 0
store i8 49, i8* %63
store i32 -1, i32* %6
br label %64
64: ; preds = %62, %59
br label %65
65: ; preds = %64, %28
%66 = load i32, i32* %6
%67 = add nsw i32 %66, 1
store i32 %67, i32* %6
%68 = load i32, i32* %2
%69 = load i32, i32* %6
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %19, i64 %70
%72 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %68, i8* %71)
%73 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
@.str = [22 x i8] c"%d in Binary is '%s'\0A\00"
define void @print_integer_in_binary(i32 %0) {
%2 = load i32, i32* @CHAR_BIT
%3 = shl i32 %2, 2
%4 = or i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @memset(i8* %6, i32 0, i32 %4)
%8 = add nsw i32 %3, -1
%9 = sext i32 %3 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
store i8 0, i8* %10
%11 = icmp eq i32 %0, 0
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = add nsw i32 %3, -2
%14 = sext i32 %8 to i64
%15 = getelementptr inbounds i8, i8* %6, i64 %14
store i8 48, i8* %15
br label %41
16: ; preds = %1
%17 = shl nsw i32 -1, %8
%18 = xor i32 %17, -1
%19 = and i32 %18, %0
%20 = icmp ult i32 %18, %0
%21 = icmp eq i32 %19, 0
br i1 %21, label %38, label %22
22: ; preds = %16
%23 = add i32 %3, -4
%24 = or i32 %23, 3
%25 = sext i32 %24 to i64
br label %26
26: ; preds = %22, %26
%27 = phi i64 [ %25, %22 ], [ %32, %26 ]
%28 = phi i32 [ %19, %22 ], [ %34, %26 ]
%29 = trunc i32 %28 to i8
%30 = and i8 %29, 1
%31 = or i8 %30, 48
%32 = add nsw i64 %27, -1
%33 = getelementptr inbounds i8, i8* %6, i64 %27
store i8 %31, i8* %33
%34 = lshr i32 %28, 1
%35 = icmp ult i32 %28, 2
br i1 %35, label %36, label %26
36: ; preds = %26
%37 = trunc i64 %32 to i32
br label %38
38: ; preds = %36, %16
%39 = phi i32 [ %8, %16 ], [ %37, %36 ]
br i1 %20, label %40, label %41
40: ; preds = %38
store i8 49, i8* %6
br label %41
41: ; preds = %38, %40, %12
%42 = phi i32 [ %13, %12 ], [ -1, %40 ], [ %39, %38 ]
%43 = add nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %6, i64 %44
%46 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %45)
ret void
}