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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void affiche_bin(short x) {
  int i, m;
  unsigned short sz = sizeof(x) * 8;
  for (i = 0, m = 0x8000; i < sz; ++i, m >>= 1) {
    printf("%i", (x & m) >> ((sz - 1) - i));
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<affiche_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movw   $0x10,-0xe(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x8000,-0xc(%rbp)
mov    -0x8(%rbp),%eax
movzwl -0xe(%rbp),%ecx
cmp    %ecx,%eax
jge    117a <affiche_bin+0x6a>
movswl -0x2(%rbp),%esi
and    -0xc(%rbp),%esi
movzwl -0xe(%rbp),%ecx
sub    $0x1,%ecx
sub    -0x8(%rbp),%ecx
sar    %cl,%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <affiche_bin+0x23>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<affiche_bin>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
movzwl %r14w,%ebp
mov    %ebp,%esi
shr    $0xf,%esi
lea    0xec9(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0xe,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0xd,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0xc,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0xb,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0xa,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0x9,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0x8,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0x7,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0x6,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0x5,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0x4,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0x3,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%esi
shr    $0x2,%esi
and    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
shr    %ebp
and    $0x1,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
and    $0x1,%r14d
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
define void @affiche_bin(i16 signext %0) {
%2 = zext i16 %0 to i32
%3 = lshr i32 %2, 15
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = lshr i32 %2, 14
%6 = and i32 %5, 1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = lshr i32 %2, 13
%9 = and i32 %8, 1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = lshr i32 %2, 12
%12 = and i32 %11, 1
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = lshr i32 %2, 11
%15 = and i32 %14, 1
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = lshr i32 %2, 10
%18 = and i32 %17, 1
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = lshr i32 %2, 9
%21 = and i32 %20, 1
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = lshr i32 %2, 8
%24 = and i32 %23, 1
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = lshr i32 %2, 7
%27 = and i32 %26, 1
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = lshr i32 %2, 6
%30 = and i32 %29, 1
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = lshr i32 %2, 5
%33 = and i32 %32, 1
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = lshr i32 %2, 4
%36 = and i32 %35, 1
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = lshr i32 %2, 3
%39 = and i32 %38, 1
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %39)
%41 = lshr i32 %2, 2
%42 = and i32 %41, 1
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = lshr i32 %2, 1
%45 = and i32 %44, 1
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %45)
%47 = and i32 %2, 1
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %47)
%49 = tail call i32 @putchar(i32 10)
ret void
}