#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 *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ single_digit_oct_to_bin(char);
char *strcat(char *, int /*<<< orphan*/);
int strlen(char *);
char *oct_to_bin(char *oct) {
  char *bin = malloc(strlen(oct) * 3 + 1);
  int i = 0;
  memset(bin, 0, strlen(oct) * 3 + 1);
  for (i = 0; i < strlen(oct); i++) {
    bin = strcat(bin, single_digit_oct_to_bin(oct[i]));
  }
  return bin;
}


x86 assembly (clang, -O0):
<oct_to_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
imul   $0x3,%eax,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
imul   $0x3,%eax,%edx
add    $0x1,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11f6 <oct_to_bin+0xa6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <single_digit_oct_to_bin@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1070 <strcat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a4 <oct_to_bin+0x54>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oct_to_bin>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
lea    (%rax,%rax,2),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rax,2),%edx
add    $0x1,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11ca <oct_to_bin+0x7a>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%edi
call   1060 <single_digit_oct_to_bin@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1070 <strcat@plt>
mov    %rax,%r15
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11a0 <oct_to_bin+0x50>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @oct_to_bin(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = mul nsw i32 %6, 3
%8 = add nsw i32 %7, 1
%9 = call i8* @malloc(i32 %8)
store i8* %9, i8** %3
store i32 0, i32* %4
%10 = load i8*, i8** %3
%11 = load i8*, i8** %2
%12 = call i32 @strlen(i8* %11)
%13 = mul nsw i32 %12, 3
%14 = add nsw i32 %13, 1
%15 = call i32 @memset(i8* %10, i32 0, i32 %14)
store i32 0, i32* %4
br label %16
16: ; preds = %30, %1
%17 = load i32, i32* %4
%18 = load i8*, i8** %2
%19 = call i32 @strlen(i8* %18)
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %33
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = load i8*, i8** %2
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = call i32 @single_digit_oct_to_bin(i8 signext %27)
%29 = call i8* @strcat(i8* %22, i32 %28)
store i8* %29, i8** %3
br label %30
30: ; preds = %21
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %16
33: ; preds = %16
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
define i8* @oct_to_bin(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = mul nsw i32 %2, 3
%4 = add nsw i32 %3, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = tail call i32 @strlen(i8* %0)
%7 = mul nsw i32 %6, 3
%8 = add nsw i32 %7, 1
%9 = tail call i32 @memset(i8* %5, i32 0, i32 %8)
%10 = tail call i32 @strlen(i8* %0)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %1, %12
%13 = phi i64 [ %19, %12 ], [ 0, %1 ]
%14 = phi i8* [ %18, %12 ], [ %5, %1 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %13
%16 = load i8, i8* %15
%17 = tail call i32 @single_digit_oct_to_bin(i8 signext %16)
%18 = tail call i8* @strcat(i8* %14, i32 %17)
%19 = add nuw nsw i64 %13, 1
%20 = tail call i32 @strlen(i8* %0)
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %12, label %23
23: ; preds = %12, %1
%24 = phi i8* [ %5, %1 ], [ %18, %12 ]
ret i8* %24
}