#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 print_bin(int n) {
  char result[32];
  int i = 0;
  int j = 0;
  if (n == 0) {
    printf("0\n");
    return;
  }
  while (n) {
    if (n & 1)
      result[i++] = '1';
    else
      result[i++] = '0';
    n >>= 1;
  }
  for (j = 10; j > i; j--) {
    printf("0");
  }
  while ((--i) >= 0) {
    if (i % 4 == 0) {
      printf("-");
    }
    printf("%c", result[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1146 <print_bin+0x36>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122d <print_bin+0x11d>
jmp    114b <print_bin+0x3b>
cmpl   $0x0,-0x4(%rbp)
je     119b <print_bin+0x8b>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     117b <print_bin+0x6b>
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x34(%rbp)
cltq
movb   $0x31,-0x30(%rbp,%rax,1)
jmp    118d <print_bin+0x7d>
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x34(%rbp)
cltq
movb   $0x30,-0x30(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    114b <print_bin+0x3b>
movl   $0xa,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jle    11ca <print_bin+0xba>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    11a2 <print_bin+0x92>
jmp    11cf <print_bin+0xbf>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jl     121f <print_bin+0x10f>
mov    -0x34(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1203 <print_bin+0xf3>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cf <print_bin+0xbf>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bin>:
test   %edi,%edi
je     11c8 <print_bin+0xa8>
push   %r14
push   %rbx
sub    $0x28,%rsp
xor    %r14d,%r14d
mov    %edi,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %edi,%ecx
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,(%rsp,%r14,1)
add    $0x1,%r14
sar    %eax
cmp    $0x2,%edi
mov    %eax,%edi
jae    1140 <print_bin+0x20>
lea    -0x1(%r14),%eax
cmp    $0x8,%eax
ja     1182 <print_bin+0x62>
mov    $0xa,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0x30,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
cmp    %r14d,%ebx
jg     1170 <print_bin+0x50>
lea    -0x1(%r14),%eax
lea    (%rsp,%rax,1),%rbx
jmp    11a1 <print_bin+0x81>
nopl   0x0(%rax)
movsbl (%rbx),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
test   %r14d,%r14d
jle    11b7 <print_bin+0x97>
add    $0xffffffff,%r14d
test   $0x3,%r14b
jne    1190 <print_bin+0x70>
mov    $0x2d,%edi
call   1030 <putchar@plt>
jmp    1190 <print_bin+0x70>
mov    $0xa,%edi
add    $0x28,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>
lea    0xe31(%rip),%rdi
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"0\0A\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @print_bin(i32 %0) {
%2 = alloca i32
%3 = alloca [32 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %61
10: ; preds = %1
br label %11
11: ; preds = %28, %10
%12 = load i32, i32* %2
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %11
%15 = load i32, i32* %2
%16 = and i32 %15, 1
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %21
store i8 49, i8* %22
br label %28
23: ; preds = %14
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %26
store i8 48, i8* %27
br label %28
28: ; preds = %23, %18
%29 = load i32, i32* %2
%30 = ashr i32 %29, 1
store i32 %30, i32* %2
br label %11
31: ; preds = %11
store i32 10, i32* %5
br label %32
32: ; preds = %38, %31
%33 = load i32, i32* %5
%34 = load i32, i32* %4
%35 = icmp sgt i32 %33, %34
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %36
%39 = load i32, i32* %5
%40 = add nsw i32 %39, -1
store i32 %40, i32* %5
br label %32
41: ; preds = %32
br label %42
42: ; preds = %52, %41
%43 = load i32, i32* %4
%44 = add nsw i32 %43, -1
store i32 %44, i32* %4
%45 = icmp sge i32 %44, 0
br i1 %45, label %46, label %59
46: ; preds = %42
%47 = load i32, i32* %4
%48 = srem i32 %47, 4
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %50, %46
%53 = load i32, i32* %4
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %57)
br label %42
59: ; preds = %42
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %61
61: ; preds = %59, %8
ret void
}

LLVM IR (-O2):
@str = [2 x i8] c"0\00"
define void @print_bin(i32 %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = icmp eq i32 %0, 0
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %44
7: ; preds = %11
%8 = trunc i64 %12 to i32
%9 = trunc i64 %18 to i32
%10 = icmp ult i32 %8, 9
br i1 %10, label %23, label %21
11: ; preds = %1, %11
%12 = phi i64 [ %18, %11 ], [ 0, %1 ]
%13 = phi i32 [ %19, %11 ], [ %0, %1 ]
%14 = and i32 %13, 1
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i8 48, i8 49
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %12
store i8 %16, i8* %17
%18 = add nuw i64 %12, 1
%19 = ashr i32 %13, 1
%20 = icmp ult i32 %13, 2
br i1 %20, label %7, label %11
21: ; preds = %23, %7
%22 = and i64 %12, 4294967295
br label %28
23: ; preds = %7, %23
%24 = phi i32 [ %26, %23 ], [ 10, %7 ]
%25 = tail call i32 @putchar(i32 48)
%26 = add nsw i32 %24, -1
%27 = icmp sgt i32 %26, %9
br i1 %27, label %23, label %21
28: ; preds = %21, %35
%29 = phi i64 [ %22, %21 ], [ %40, %35 ]
%30 = trunc i64 %29 to i32
%31 = and i32 %30, 3
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = tail call i32 @putchar(i32 45)
br label %35
35: ; preds = %33, %28
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %29
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = tail call i32 @putchar(i32 %38)
%40 = add nsw i64 %29, -1
%41 = icmp sgt i32 %30, 0
br i1 %41, label %28, label %42
42: ; preds = %35
%43 = tail call i32 @putchar(i32 10)
br label %44
44: ; preds = %42, %5
ret void
}