#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 */
char *intToBinary(int n, char *buffer, size_t size) {
  buffer += (size - 1);
  for (int i = 31; i >= 0; i--) {
    *buffer-- = (n & 1) + '0';
    n >>= 1;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<intToBinary>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x1f,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1163 <intToBinary+0x63>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1126 <intToBinary+0x26>
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<intToBinary>:
mov    %rsi,%rax
add    %rdx,%rax
mov    $0xffffffffffffffff,%rcx
nopl   (%rax)
mov    %edi,%edx
and    $0x1,%dl
or     $0x30,%dl
mov    %dl,(%rax,%rcx,1)
mov    %edi,%edx
shr    %dl
and    $0x1,%dl
or     $0x30,%dl
mov    %dl,-0x1(%rax,%rcx,1)
mov    %edi,%edx
shr    $0x2,%dl
and    $0x1,%dl
or     $0x30,%dl
mov    %dl,-0x2(%rax,%rcx,1)
mov    %edi,%edx
shr    $0x3,%dl
and    $0x1,%dl
or     $0x30,%dl
mov    %dl,-0x3(%rax,%rcx,1)
sar    $0x4,%edi
add    $0xfffffffffffffffc,%rcx
cmp    $0xffffffdf,%ecx
jne    1110 <intToBinary+0x10>
add    %rcx,%rax
ret

LLVM IR (-O0):
define i8* @intToBinary(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i64, i64* %6
%9 = sub i64 %8, 1
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i64 %9
store i8* %11, i8** %5
store i32 31, i32* %7
br label %12
12: ; preds = %24, %3
%13 = load i32, i32* %7
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %27
15: ; preds = %12
%16 = load i32, i32* %4
%17 = and i32 %16, 1
%18 = add nsw i32 %17, 48
%19 = trunc i32 %18 to i8
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 -1
store i8* %21, i8** %5
store i8 %19, i8* %20
%22 = load i32, i32* %4
%23 = ashr i32 %22, 1
store i32 %23, i32* %4
br label %24
24: ; preds = %15
%25 = load i32, i32* %7
%26 = add nsw i32 %25, -1
store i32 %26, i32* %7
br label %12
27: ; preds = %12
%28 = load i8*, i8** %5
ret i8* %28
}

LLVM IR (-O2):
define i8* @intToBinary(i32 %0, i8* writeonly %1, i64 %2) {
%4 = add i64 %2, -1
%5 = getelementptr inbounds i8, i8* %1, i64 %4
br label %7
6: ; preds = %7
ret i8* %29
7: ; preds = %7, %3
%8 = phi i32 [ 31, %3 ], [ %31, %7 ]
%9 = phi i32 [ %0, %3 ], [ %30, %7 ]
%10 = phi i8* [ %5, %3 ], [ %29, %7 ]
%11 = trunc i32 %9 to i8
%12 = and i8 %11, 1
%13 = or i8 %12, 48
%14 = getelementptr inbounds i8, i8* %10, i64 -1
store i8 %13, i8* %10
%15 = trunc i32 %9 to i8
%16 = lshr i8 %15, 1
%17 = and i8 %16, 1
%18 = or i8 %17, 48
%19 = getelementptr inbounds i8, i8* %10, i64 -2
store i8 %18, i8* %14
%20 = trunc i32 %9 to i8
%21 = lshr i8 %20, 2
%22 = and i8 %21, 1
%23 = or i8 %22, 48
%24 = getelementptr inbounds i8, i8* %10, i64 -3
store i8 %23, i8* %19
%25 = trunc i32 %9 to i8
%26 = lshr i8 %25, 3
%27 = and i8 %26, 1
%28 = or i8 %27, 48
%29 = getelementptr inbounds i8, i8* %10, i64 -4
store i8 %28, i8* %24
%30 = ashr i32 %9, 4
%31 = add nsw i32 %8, -4
%32 = icmp eq i32 %8, 3
br i1 %32, label %6, label %7
}