#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 *);
int /*<<< orphan*/ strcat(char *, char *);
char *strrev(char *);
void oct2bin(unsigned oct) {
  char bin[32];
  bin[0] = '\0';
  do {
    switch (oct % 10) {
    case 0:
      strcat(bin, "000");
      break;
    case 1:
      strcat(bin, "100");
      break;
    case 2:
      strcat(bin, "010");
      break;
    case 3:
      strcat(bin, "110");
      break;
    case 4:
      strcat(bin, "001");
      break;
    case 5:
      strcat(bin, "101");
      break;
    case 6:
      strcat(bin, "011");
      break;
    case 7:
      strcat(bin, "111");
      break;
    }
  } while (oct /= 10);
  printf("= %s in binary.", strrev(bin));
}


x86 assembly (clang, -O0):
<oct2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x0,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
mov    %ecx,%eax
mov    $0xcccccccd,%edx
imul   %rdx,%rcx
shr    $0x23,%rcx
mov    %ecx,%edx
add    %edx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x7,%eax
ja     1224 <oct2bin+0xf4>
mov    -0x38(%rbp),%rax
lea    0xe88(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x30(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1050 <strcat@plt>
jmp    1224 <oct2bin+0xf4>
lea    -0x30(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1050 <strcat@plt>
jmp    1224 <oct2bin+0xf4>
lea    -0x30(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1050 <strcat@plt>
jmp    1224 <oct2bin+0xf4>
lea    -0x30(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1050 <strcat@plt>
jmp    1224 <oct2bin+0xf4>
lea    -0x30(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1050 <strcat@plt>
jmp    1224 <oct2bin+0xf4>
lea    -0x30(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1050 <strcat@plt>
jmp    1224 <oct2bin+0xf4>
lea    -0x30(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1050 <strcat@plt>
jmp    1224 <oct2bin+0xf4>
lea    -0x30(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1050 <strcat@plt>
jmp    1229 <oct2bin+0xf9>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jne    113f <oct2bin+0xf>
lea    -0x30(%rbp),%rdi
call   1040 <strrev@plt>
mov    %rax,%rsi
lea    0xdec(%rip),%rdi
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oct2bin>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebp
movb   $0x0,(%rsp)
mov    $0xcccccccd,%r15d
lea    0xee1(%rip),%r12
mov    %rsp,%r14
jmp    1167 <oct2bin+0x37>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x9,%ebp
mov    %ebx,%ebp
jbe    1193 <oct2bin+0x63>
mov    %ebp,%ebx
imul   %r15,%rbx
shr    $0x23,%rbx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%ecx
mov    %ebp,%eax
sub    %ecx,%eax
cmp    $0x7,%eax
ja     1160 <oct2bin+0x30>
mov    %eax,%eax
movslq (%r12,%rax,4),%rsi
add    %r12,%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
jmp    1160 <oct2bin+0x30>
mov    %rsp,%rdi
call   1040 <strrev@plt>
lea    0xe7e(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"000\00"
@.str.1 = [4 x i8] c"100\00"
@.str.2 = [4 x i8] c"010\00"
@.str.3 = [4 x i8] c"110\00"
@.str.4 = [4 x i8] c"001\00"
@.str.5 = [4 x i8] c"101\00"
@.str.6 = [4 x i8] c"011\00"
@.str.7 = [4 x i8] c"111\00"
@.str.8 = [16 x i8] c"= %s in binary.\00"
define void @oct2bin(i32 %0) {
%2 = alloca i32
%3 = alloca [32 x i8]
store i32 %0, i32* %2
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
store i8 0, i8* %4
br label %5
5: ; preds = %33, %1
%6 = load i32, i32* %2
%7 = urem i32 %6, 10
switch i32 %7, label %32 [
i32 0, label %8
i32 1, label %11
i32 2, label %14
i32 3, label %17
i32 4, label %20
i32 5, label %23
i32 6, label %26
i32 7, label %29
]
8: ; preds = %5
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%10 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %32
11: ; preds = %5
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%13 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %32
14: ; preds = %5
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%16 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %32
17: ; preds = %5
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%19 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %32
20: ; preds = %5
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%22 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %32
23: ; preds = %5
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %32
26: ; preds = %5
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%28 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %32
29: ; preds = %5
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%31 = call i32 @strcat(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
br label %32
32: ; preds = %5, %29, %26, %23, %20, %17, %14, %11, %8
br label %33
33: ; preds = %32
%34 = load i32, i32* %2
%35 = udiv i32 %34, 10
store i32 %35, i32* %2
%36 = icmp ne i32 %35, 0
br i1 %36, label %5, label %37
37: ; preds = %33
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%39 = call i8* @strrev(i8* %38)
%40 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* %39)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"000\00"
@.str.1 = [4 x i8] c"100\00"
@.str.2 = [4 x i8] c"010\00"
@.str.3 = [4 x i8] c"110\00"
@.str.4 = [4 x i8] c"001\00"
@.str.5 = [4 x i8] c"101\00"
@.str.6 = [4 x i8] c"011\00"
@.str.7 = [4 x i8] c"111\00"
@.str.8 = [16 x i8] c"= %s in binary.\00"
@reltable.oct2bin = [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str to i64), i64 ptrtoint ([8 x i32]* @reltable.oct2bin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.oct2bin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([8 x i32]* @reltable.oct2bin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.3 to i64), i64 ptrtoint ([8 x i32]* @reltable.oct2bin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.oct2bin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.oct2bin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.6 to i64), i64 ptrtoint ([8 x i32]* @reltable.oct2bin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.7 to i64), i64 ptrtoint ([8 x i32]* @reltable.oct2bin to i64)) to i32)]
define void @oct2bin(i32 %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
store i8 0, i8* %3
br label %4
4: ; preds = %14, %1
%5 = phi i32 [ %0, %1 ], [ %7, %14 ]
%6 = urem i32 %5, 10
%7 = udiv i32 %5, 10
%8 = icmp ult i32 %6, 8
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = zext i32 %6 to i64
%11 = shl i64 %10, 2
%12 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.oct2bin to i8*), i64 %11)
%13 = call i32 @strcat(i8* %3, i8* %12)
br label %14
14: ; preds = %4, %9
%15 = icmp ult i32 %5, 10
br i1 %15, label %16, label %4
16: ; preds = %14
%17 = call i8* @strrev(i8* %3)
%18 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* %17)
ret void
}