#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 *, char);
void ctoi(int n, char arr[]) {
  int i;
  for (i = 7; i >= 0; i--) {
    arr[i] = n % 2;
    n /= 2;
  }
  for (i = 0; i < 8; i++) {
    printf("%d", arr[i]);
  }
}


x86 assembly (clang, -O0):
<ctoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x7,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1162 <ctoi+0x52>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <ctoi+0x16>
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    1199 <ctoi+0x89>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
lea    0xe7e(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1169 <ctoi+0x59>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ctoi>:
push   %r15
push   %r14
push   %rbx
lea    0x7f(%rdi),%r8d
test   %edi,%edi
cmovns %edi,%r8d
lea    0x3f(%rdi),%r9d
test   %edi,%edi
cmovns %edi,%r9d
lea    0x1f(%rdi),%edx
test   %edi,%edi
cmovns %edi,%edx
lea    0xf(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
lea    0x7(%rdi),%ebx
test   %edi,%edi
cmovns %edi,%ebx
lea    0x3(%rdi),%ecx
test   %edi,%edi
cmovns %edi,%ecx
mov    %rsi,%r15
mov    %edi,%esi
shr    $0x1f,%esi
add    %edi,%esi
sar    %esi
sar    $0x2,%ecx
sar    $0x3,%ebx
movd   %ecx,%xmm0
movd   %ebx,%xmm1
punpckldq %xmm0,%xmm1
movd   %esi,%xmm0
movd   %edi,%xmm2
punpckldq %xmm2,%xmm0
punpcklqdq %xmm0,%xmm1
movdqa %xmm1,%xmm0
psrld  $0x1f,%xmm0
paddd  %xmm1,%xmm0
psrad  $0x1,%xmm0
paddd  %xmm0,%xmm0
psubd  %xmm0,%xmm1
pand   0xe67(%rip),%xmm1
packuswb %xmm1,%xmm1
packuswb %xmm1,%xmm1
movd   %xmm1,0x4(%r15)
mov    %eax,%ecx
sar    $0x4,%ecx
shr    $0x1f,%eax
add    %ecx,%eax
and    $0xfe,%eax
sub    %eax,%ecx
mov    %cl,0x3(%r15)
mov    %edx,%eax
sar    $0x5,%eax
shr    $0x1f,%edx
add    %eax,%edx
and    $0xfe,%edx
sub    %edx,%eax
mov    %al,0x2(%r15)
mov    %r9d,%eax
sar    $0x6,%eax
shr    $0x1f,%r9d
add    %eax,%r9d
and    $0xfe,%r9d
sub    %r9d,%eax
mov    %al,0x1(%r15)
mov    %r8d,%eax
sar    $0x7,%eax
shr    $0x1f,%r8d
add    %eax,%r8d
and    $0xfffffffe,%r8d
sub    %r8d,%eax
mov    %al,(%r15)
movsbl %al,%esi
lea    0xe02(%rip),%r14
mov    %r14,%rdi
call   1030 <printf@plt>
movsbl 0x1(%r15),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movsbl 0x2(%r15),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movsbl 0x3(%r15),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movsbl 0x4(%r15),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movsbl 0x5(%r15),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movsbl 0x6(%r15),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movsbl 0x7(%r15),%esi
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define void @ctoi(i32 %0, i8* nocapture %1) {
%3 = getelementptr inbounds i8, i8* %1, i64 7
%4 = sdiv i32 %0, 2
%5 = getelementptr inbounds i8, i8* %1, i64 6
%6 = sdiv i32 %0, 4
%7 = getelementptr inbounds i8, i8* %1, i64 5
%8 = sdiv i32 %0, 8
%9 = insertelement <4 x i32> poison, i32 %0, i64 3
%10 = insertelement <4 x i32> %9, i32 %8, i64 0
%11 = insertelement <4 x i32> %10, i32 %6, i64 1
%12 = insertelement <4 x i32> %11, i32 %4, i64 2
%13 = srem <4 x i32> %12, <i32 2, i32 2, i32 2, i32 2>
%14 = trunc <4 x i32> %13 to <4 x i8>
%15 = getelementptr inbounds i8, i8* %1, i64 4
%16 = bitcast i8* %15 to <4 x i8>*
store <4 x i8> %14, <4 x i8>* %16
%17 = sdiv i32 %0, 16
%18 = srem i32 %17, 2
%19 = trunc i32 %18 to i8
%20 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %19, i8* %20
%21 = sdiv i32 %0, 32
%22 = srem i32 %21, 2
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %23, i8* %24
%25 = sdiv i32 %0, 64
%26 = srem i32 %25, 2
%27 = trunc i32 %26 to i8
%28 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %27, i8* %28
%29 = sdiv i32 %0, 128
%30 = srem i32 %29, 2
%31 = trunc i32 %30 to i8
store i8 %31, i8* %1
%32 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %31)
%33 = load i8, i8* %28
%34 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %33)
%35 = load i8, i8* %24
%36 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %35)
%37 = load i8, i8* %20
%38 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %37)
%39 = load i8, i8* %15
%40 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %39)
%41 = load i8, i8* %7
%42 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %41)
%43 = load i8, i8* %5
%44 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %43)
%45 = load i8, i8* %3
%46 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %45)
ret void
}