#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 /*<<< orphan*/ scanf(char *, char *);
int octtobin() {
  char octnum[100];
  int i = 0;
  printf("Enter octal value: ");
  scanf("%s", octnum);
  printf("Binary: ");
  while (octnum[i]) {
    switch (octnum[i]) {
    case '0':
      printf("000");
      break;
    case '1':
      printf("001");
      break;
    case '2':
      printf("010");
      break;
    case '3':
      printf("011");
      break;
    case '4':
      printf("100");
      break;
    case '5':
      printf("101");
      break;
    case '6':
      printf("110");
      break;
    case '7':
      printf("111");
      break;
    default:
      printf("Not correct input");
    }
    i++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<octtobin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x74(%rbp)
lea    0xee7(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xeeb(%rip),%rdi
call   1040 <scanf@plt>
lea    0xee2(%rip),%rdi
call   1030 <printf@plt>
movslq -0x74(%rbp),%rax
cmpb   $0x0,-0x70(%rbp,%rax,1)
je     123a <octtobin+0x11a>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
add    $0xffffffd0,%eax
mov    %eax,%ecx
mov    %rcx,-0x80(%rbp)
sub    $0x7,%eax
ja     1220 <octtobin+0x100>
mov    -0x80(%rbp),%rax
lea    0xe71(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
jmp    122c <octtobin+0x10c>
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
jmp    122c <octtobin+0x10c>
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
jmp    122c <octtobin+0x10c>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
jmp    122c <octtobin+0x10c>
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
jmp    122c <octtobin+0x10c>
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
jmp    122c <octtobin+0x10c>
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
jmp    122c <octtobin+0x10c>
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
jmp    122c <octtobin+0x10c>
lea    0xe39(%rip),%rdi
call   1030 <printf@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    115a <octtobin+0x3a>
mov    $0x1,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<octtobin>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
lea    0xed0(%rip),%rdi
call   1030 <printf@plt>
lea    0xed8(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
lea    0xecc(%rip),%rdi
call   1030 <printf@plt>
mov    (%rsp),%al
test   %al,%al
je     1199 <octtobin+0x79>
lea    0x1(%rsp),%rbx
lea    0xedd(%rip),%r14
lea    0xeea(%rip),%r15
jmp    1180 <octtobin+0x60>
nopl   0x0(%rax)
call   1030 <printf@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1199 <octtobin+0x79>
movsbl %al,%eax
add    $0xffffffd0,%eax
mov    %r14,%rdi
cmp    $0x7,%eax
ja     1170 <octtobin+0x50>
cltq
movslq (%r15,%rax,4),%rdi
add    %r15,%rdi
jmp    1170 <octtobin+0x50>
mov    $0x1,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter octal value: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [9 x i8] c"Binary: \00"
@.str.3 = [4 x i8] c"000\00"
@.str.4 = [4 x i8] c"001\00"
@.str.5 = [4 x i8] c"010\00"
@.str.6 = [4 x i8] c"011\00"
@.str.7 = [4 x i8] c"100\00"
@.str.8 = [4 x i8] c"101\00"
@.str.9 = [4 x i8] c"110\00"
@.str.10 = [4 x i8] c"111\00"
@.str.11 = [18 x i8] c"Not correct input\00"
define i32 @octtobin() {
%1 = alloca [100 x i8]
%2 = alloca i32
store i32 0, i32* %2
%3 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%6 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %7
7: ; preds = %37, %0
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %40
13: ; preds = %7
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
switch i32 %18, label %35 [
i32 48, label %19
i32 49, label %21
i32 50, label %23
i32 51, label %25
i32 52, label %27
i32 53, label %29
i32 54, label %31
i32 55, label %33
]
19: ; preds = %13
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %37
21: ; preds = %13
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %37
23: ; preds = %13
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %37
25: ; preds = %13
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %37
27: ; preds = %13
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
br label %37
29: ; preds = %13
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %37
31: ; preds = %13
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
br label %37
33: ; preds = %13
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
br label %37
35: ; preds = %13
%36 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0))
br label %37
37: ; preds = %35, %33, %31, %29, %27, %25, %23, %21, %19
%38 = load i32, i32* %2
%39 = add nsw i32 %38, 1
store i32 %39, i32* %2
br label %7
40: ; preds = %7
ret i32 1
}

LLVM IR (-O2):
@.str = [20 x i8] c"Enter octal value: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [9 x i8] c"Binary: \00"
@.str.3 = [4 x i8] c"000\00"
@.str.4 = [4 x i8] c"001\00"
@.str.5 = [4 x i8] c"010\00"
@.str.6 = [4 x i8] c"011\00"
@.str.7 = [4 x i8] c"100\00"
@.str.8 = [4 x i8] c"101\00"
@.str.9 = [4 x i8] c"110\00"
@.str.10 = [4 x i8] c"111\00"
@.str.11 = [18 x i8] c"Not correct input\00"
@reltable.octtobin = [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.3 to i64), i64 ptrtoint ([8 x i32]* @reltable.octtobin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.octtobin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.octtobin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.6 to i64), i64 ptrtoint ([8 x i32]* @reltable.octtobin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.7 to i64), i64 ptrtoint ([8 x i32]* @reltable.octtobin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.8 to i64), i64 ptrtoint ([8 x i32]* @reltable.octtobin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.9 to i64), i64 ptrtoint ([8 x i32]* @reltable.octtobin to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.10 to i64), i64 ptrtoint ([8 x i32]* @reltable.octtobin to i64)) to i32)]
define i32 @octtobin() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 0
br i1 %7, label %25, label %8
8: ; preds = %0, %18
%9 = phi i64 [ %21, %18 ], [ 0, %0 ]
%10 = phi i8 [ %23, %18 ], [ %6, %0 ]
%11 = sext i8 %10 to i32
%12 = add nsw i32 %11, -48
%13 = icmp ult i32 %12, 8
br i1 %13, label %14, label %18
14: ; preds = %8
%15 = sext i32 %12 to i64
%16 = shl i64 %15, 2
%17 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.octtobin to i8*), i64 %16)
br label %18
18: ; preds = %8, %14
%19 = phi i8* [ %17, %14 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), %8 ]
%20 = call i32 @printf(i8* dereferenceable(1) %19)
%21 = add nuw i64 %9, 1
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %8
25: ; preds = %18, %0
ret i32 1
}