#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 */
unsigned long long floor(unsigned long long);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
void dec_to_octal(unsigned long long dec, char *octal) {
  char sdec[12] = {0};
  char soctal[12] = {0};
  int d[12] = {0};
  int i;
  unsigned long long working = dec;
  sprintf(sdec, "%llu", dec);
  while (working > 0) {
    unsigned long long w = floor(working / 8);
    d[i] = working % 8;
    working = w;
    i++;
  }
  while (i >= 0) {
    char c[2];
    sprintf(c, "%d", d[i]);
    if (i <= (int)strlen(sdec)) {
      strcat(soctal, c);
    }
    i--;
  }
  strcpy(octal, soctal);
}


x86 assembly (clang, -O0):
<dec_to_octal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1c(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    -0x1c(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    %eax,%edx
lea    0xe44(%rip),%rsi
call   1070 <sprintf@plt>
cmpq   $0x0,-0x70(%rbp)
jbe    1205 <dec_to_octal+0xa5>
mov    -0x70(%rbp),%rdi
shr    $0x3,%rdi
call   1080 <floor@plt>
mov    %rax,-0x78(%rbp)
mov    -0x70(%rbp),%rax
and    $0x7,%rax
mov    %eax,%ecx
movslq -0x64(%rbp),%rax
mov    %ecx,-0x60(%rbp,%rax,4)
mov    -0x78(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11c1 <dec_to_octal+0x61>
jmp    120a <dec_to_octal+0xaa>
cmpl   $0x0,-0x64(%rbp)
jl     1264 <dec_to_octal+0x104>
lea    -0x7a(%rbp),%rdi
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edx
lea    0xdde(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x64(%rbp),%eax
mov    %eax,-0x80(%rbp)
lea    -0x1c(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x80(%rbp),%eax
cmp    %ecx,%eax
jg     1256 <dec_to_octal+0xf6>
lea    -0x28(%rbp),%rdi
lea    -0x7a(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
jmp    120a <dec_to_octal+0xaa>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec_to_octal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,0x28(%rsp)
movq   $0x0,0x20(%rsp)
movl   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
lea    0xe61(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    %ebx,%edx
call   1060 <sprintf@plt>
test   %rbx,%rbx
je     1247 <dec_to_octal+0xf7>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
shr    $0x3,%rdi
call   1070 <floor@plt>
and    $0x7,%ebx
mov    %ebx,0x30(%rsp,%rbp,4)
add    $0x1,%rbp
mov    %rax,%rbx
test   %rax,%rax
jne    11c0 <dec_to_octal+0x70>
test   $0x80000000,%ebp
jne    1247 <dec_to_octal+0xf7>
mov    %ebp,%ebp
lea    0xe15(%rip),%r15
lea    0xe(%rsp),%rbx
lea    0x20(%rsp),%r12
lea    0x10(%rsp),%r13
jmp    121c <dec_to_octal+0xcc>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbp),%rax
test   %rbp,%rbp
mov    %rax,%rbp
jle    1247 <dec_to_octal+0xf7>
mov    0x30(%rsp,%rbp,4),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <sprintf@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jg     1210 <dec_to_octal+0xc0>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
jmp    1210 <dec_to_octal+0xc0>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%llu\00"
@.str.1 = [3 x i8] c"%d\00"
define void @dec_to_octal(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca [12 x i8]
%6 = alloca [12 x i8]
%7 = alloca [12 x i32]
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca [2 x i8]
store i64 %0, i64* %3
store i8* %1, i8** %4
%12 = bitcast [12 x i8]* %5 to i8*
%13 = bitcast [12 x i8]* %6 to i8*
%14 = bitcast [12 x i32]* %7 to i8*
%15 = load i64, i64* %3
store i64 %15, i64* %9
%16 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%17 = load i64, i64* %3
%18 = trunc i64 %17 to i32
%19 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %23, %2
%21 = load i64, i64* %9
%22 = icmp ugt i64 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %20
%24 = load i64, i64* %9
%25 = udiv i64 %24, 8
%26 = call i64 @floor(i64 %25)
store i64 %26, i64* %10
%27 = load i64, i64* %9
%28 = urem i64 %27, 8
%29 = trunc i64 %28 to i32
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [12 x i32], [12 x i32]* %7, i64 0, i64 %31
store i32 %29, i32* %32
%33 = load i64, i64* %10
store i64 %33, i64* %9
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %20
36: ; preds = %20
br label %37
37: ; preds = %56, %36
%38 = load i32, i32* %8
%39 = icmp sge i32 %38, 0
br i1 %39, label %40, label %59
40: ; preds = %37
%41 = getelementptr inbounds [2 x i8], [2 x i8]* %11, i64 0, i64 0
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [12 x i32], [12 x i32]* %7, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %8
%48 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%49 = call i64 @strlen(i8* %48)
%50 = trunc i64 %49 to i32
%51 = icmp sle i32 %47, %50
br i1 %51, label %52, label %56
52: ; preds = %40
%53 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%54 = getelementptr inbounds [2 x i8], [2 x i8]* %11, i64 0, i64 0
%55 = call i32 @strcat(i8* %53, i8* %54)
br label %56
56: ; preds = %52, %40
%57 = load i32, i32* %8
%58 = add nsw i32 %57, -1
store i32 %58, i32* %8
br label %37
59: ; preds = %37
%60 = load i8*, i8** %4
%61 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%62 = call i32 @strcpy(i8* %60, i8* %61)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%llu\00"
@.str.1 = [3 x i8] c"%d\00"
define void @dec_to_octal(i64 %0, i8* %1) {
%3 = alloca [12 x i8]
%4 = alloca [12 x i8]
%5 = alloca [12 x i32]
%6 = alloca [2 x i8]
%7 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%9 = bitcast [12 x i32]* %5 to i8*
%10 = trunc i64 %0 to i32
%11 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp eq i64 %0, 0
br i1 %12, label %43, label %19
13: ; preds = %19
%14 = and i64 %27, 2147483648
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %43
16: ; preds = %13
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%18 = and i64 %27, 4294967295
br label %29
19: ; preds = %2, %19
%20 = phi i64 [ %27, %19 ], [ 0, %2 ]
%21 = phi i64 [ %23, %19 ], [ %0, %2 ]
%22 = lshr i64 %21, 3
%23 = tail call i64 @floor(i64 %22)
%24 = trunc i64 %21 to i32
%25 = and i32 %24, 7
%26 = getelementptr inbounds [12 x i32], [12 x i32]* %5, i64 0, i64 %20
store i32 %25, i32* %26
%27 = add i64 %20, 1
%28 = icmp eq i64 %23, 0
br i1 %28, label %13, label %19
29: ; preds = %16, %40
%30 = phi i64 [ %18, %16 ], [ %41, %40 ]
%31 = getelementptr inbounds [12 x i32], [12 x i32]* %5, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = call i32 @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = call i64 @strlen(i8* %7)
%35 = shl i64 %34, 32
%36 = ashr exact i64 %35, 32
%37 = icmp sgt i64 %30, %36
br i1 %37, label %40, label %38
38: ; preds = %29
%39 = call i32 @strcat(i8* %8, i8* %17)
br label %40
40: ; preds = %38, %29
%41 = add nsw i64 %30, -1
%42 = icmp sgt i64 %30, 0
br i1 %42, label %29, label %43
43: ; preds = %40, %2, %13
%44 = call i32 @strcpy(i8* %1, i8* %8)
ret void
}