#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 bin(short d) {
  int i;
  for (i = 7; i >= 0; i--) {
    if ((1 << i) & d)
      printf("1");
    else
      printf("0");
  }
}


x86 assembly (clang, -O0):
<bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movl   $0x7,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1179 <bin+0x69>
mov    -0x8(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
movswl -0x2(%rbp),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     115a <bin+0x4a>
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
jmp    1166 <bin+0x56>
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
jmp    116b <bin+0x5b>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1126 <bin+0x16>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %edi,%eax
and    $0x80,%eax
cmp    $0x1,%eax
mov    $0x31,%ebp
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x40,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x20,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x10,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x8,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x4,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x2,%eax
cmp    $0x1,%eax
sbb    $0x0,%ebp
mov    %ebp,%edi
call   1030 <putchar@plt>
and    $0x1,%ebx
or     $0x30,%ebx
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
define void @bin(i16 signext %0) {
%2 = zext i16 %0 to i32
%3 = and i32 %2, 128
%4 = icmp eq i32 %3, 0
%5 = select i1 %4, i32 48, i32 49
%6 = tail call i32 @putchar(i32 %5)
%7 = and i32 %2, 64
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i32 48, i32 49
%10 = tail call i32 @putchar(i32 %9)
%11 = and i32 %2, 32
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 48, i32 49
%14 = tail call i32 @putchar(i32 %13)
%15 = and i32 %2, 16
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i32 48, i32 49
%18 = tail call i32 @putchar(i32 %17)
%19 = and i32 %2, 8
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i32 48, i32 49
%22 = tail call i32 @putchar(i32 %21)
%23 = and i32 %2, 4
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i32 48, i32 49
%26 = tail call i32 @putchar(i32 %25)
%27 = and i32 %2, 2
%28 = icmp eq i32 %27, 0
%29 = select i1 %28, i32 48, i32 49
%30 = tail call i32 @putchar(i32 %29)
%31 = and i32 %2, 1
%32 = or i32 %31, 48
%33 = tail call i32 @putchar(i32 %32)
ret void
}