#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 *, int);
void binString(int r) {
  int bin[17];
  int x, y;
  for (x = 0; r > 0; x++) {
    bin[x] = r % 2;
    r >>= 1;
  }
  bin[x] = '\0';
  for (y = x - 1; y >= 0; y--)
    printf("%d", bin[y]);
}


x86 assembly (clang, -O0):
<binString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1156 <binString+0x46>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq -0x54(%rbp),%rax
mov    %edx,-0x50(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1122 <binString+0x12>
movslq -0x54(%rbp),%rax
movl   $0x0,-0x50(%rbp,%rax,4)
mov    -0x54(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x58(%rbp)
cmpl   $0x0,-0x58(%rbp)
jl     1197 <binString+0x87>
movslq -0x58(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%esi
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x58(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x58(%rbp)
jmp    116b <binString+0x5b>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binString>:
push   %r14
push   %rbx
sub    $0x48,%rsp
test   %edi,%edi
jle    1166 <binString+0x56>
xor    %ebx,%ebx
mov    %edi,%eax
nop
mov    %edi,%ecx
and    $0x1,%ecx
mov    %ecx,(%rsp,%rbx,4)
shr    %eax
add    $0x1,%rbx
cmp    $0x1,%edi
mov    %eax,%edi
ja     1120 <binString+0x10>
movl   $0x0,(%rsp,%rbx,4)
test   %ebx,%ebx
jle    1166 <binString+0x56>
add    $0x1,%rbx
lea    0xeb5(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    -0x8(%rsp,%rbx,4),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1150 <binString+0x40>
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define void @binString(i32 %0) {
%2 = alloca i32
%3 = alloca [17 x i32]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %6
6: ; preds = %17, %1
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = load i32, i32* %2
%11 = srem i32 %10, 2
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [17 x i32], [17 x i32]* %3, i64 0, i64 %13
store i32 %11, i32* %14
%15 = load i32, i32* %2
%16 = ashr i32 %15, 1
store i32 %16, i32* %2
br label %17
17: ; preds = %9
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %6
20: ; preds = %6
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [17 x i32], [17 x i32]* %3, i64 0, i64 %22
store i32 0, i32* %23
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 1
store i32 %25, i32* %5
br label %26
26: ; preds = %35, %20
%27 = load i32, i32* %5
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %26
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [17 x i32], [17 x i32]* %3, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %29
%36 = load i32, i32* %5
%37 = add nsw i32 %36, -1
store i32 %37, i32* %5
br label %26
38: ; preds = %26
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define void @binString(i32 %0) {
%2 = alloca [17 x i32]
%3 = bitcast [17 x i32]* %2 to i8*
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %25
5: ; preds = %1, %5
%6 = phi i64 [ %11, %5 ], [ 0, %1 ]
%7 = phi i32 [ %10, %5 ], [ %0, %1 ]
%8 = and i32 %7, 1
%9 = getelementptr inbounds [17 x i32], [17 x i32]* %2, i64 0, i64 %6
store i32 %8, i32* %9
%10 = lshr i32 %7, 1
%11 = add nuw nsw i64 %6, 1
%12 = icmp ult i32 %7, 2
br i1 %12, label %13, label %5
13: ; preds = %5
%14 = trunc i64 %11 to i32
%15 = and i64 %11, 4294967295
%16 = getelementptr inbounds [17 x i32], [17 x i32]* %2, i64 0, i64 %15
store i32 0, i32* %16
%17 = icmp sgt i32 %14, 0
br i1 %17, label %18, label %25
18: ; preds = %13, %18
%19 = phi i64 [ %20, %18 ], [ %15, %13 ]
%20 = add nsw i64 %19, -1
%21 = getelementptr inbounds [17 x i32], [17 x i32]* %2, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = icmp ugt i64 %19, 1
br i1 %24, label %18, label %25
25: ; preds = %18, %1, %13
ret void
}