#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 *, ...);
void dec2oct(int decimal) {
  int remainder[32];
  int quocient = decimal, i = 0;
  while (quocient >= 7) {
    remainder[i] = quocient % 8;
    quocient = quocient / 8;
    i++;
  }
  remainder[i] = quocient;
  printf("The decimal number %d in octal is: ", decimal);
  while (i >= 0) {
    printf("%d", remainder[i]);
    i--;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dec2oct>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
cmpl   $0x7,-0x94(%rbp)
jl     1182 <dec2oct+0x72>
mov    -0x94(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
movslq -0x98(%rbp),%rax
mov    %edx,-0x90(%rbp,%rax,4)
mov    -0x94(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x94(%rbp)
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    1131 <dec2oct+0x21>
mov    -0x94(%rbp),%ecx
movslq -0x98(%rbp),%rax
mov    %ecx,-0x90(%rbp,%rax,4)
mov    -0x4(%rbp),%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x98(%rbp)
jl     11e4 <dec2oct+0xd4>
movslq -0x98(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x98(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x98(%rbp)
jmp    11a7 <dec2oct+0x97>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec2oct>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %edi,%r14d
cmp    $0x7,%edi
jl     1174 <dec2oct+0x54>
xor    %ebx,%ebx
mov    %r14d,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
mov    %ebp,%ecx
and    $0x7,%ecx
mov    %ecx,(%rsp,%rbx,4)
shr    $0x3,%ebp
add    $0x1,%rbx
cmp    $0x37,%eax
ja     1140 <dec2oct+0x20>
mov    %ebp,(%rsp,%rbx,4)
lea    0xea0(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x80000000,%ebx
je     118e <dec2oct+0x6e>
jmp    11c8 <dec2oct+0xa8>
mov    %r14d,(%rsp)
lea    0xe81(%rip),%rdi
xor    %ebx,%ebx
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%ebp
lea    0xe8f(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %rbx,%rbx
je     11c8 <dec2oct+0xa8>
add    $0x1,%rbx
lea    0xe76(%rip),%rbp
xchg   %ax,%ax
mov    -0x8(%rsp,%rbx,4),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jg     11b0 <dec2oct+0x90>
mov    $0xa,%edi
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [36 x i8] c"The decimal number %d in octal is: \00"
@.str.1 = [3 x i8] c"%d\00"
define void @dec2oct(i32 %0) {
%2 = alloca [32 x i32]
%3 = bitcast [32 x i32]* %2 to i8*
%4 = icmp sgt i32 %0, 6
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 0
store i32 %0, i32* %6
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %22
8: ; preds = %1, %8
%9 = phi i64 [ %14, %8 ], [ 0, %1 ]
%10 = phi i32 [ %13, %8 ], [ %0, %1 ]
%11 = and i32 %10, 7
%12 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 %9
store i32 %11, i32* %12
%13 = lshr i32 %10, 3
%14 = add nuw nsw i64 %9, 1
%15 = icmp ugt i32 %10, 55
br i1 %15, label %8, label %16
16: ; preds = %8
%17 = and i64 %14, 4294967295
%18 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 %17
store i32 %13, i32* %18
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %0)
%20 = and i64 %14, 2147483648
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %5, %16
%23 = phi i64 [ 0, %5 ], [ %17, %16 ]
%24 = phi i32 [ %0, %5 ], [ %13, %16 ]
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = icmp eq i64 %23, 0
br i1 %26, label %34, label %27
27: ; preds = %22, %27
%28 = phi i64 [ %29, %27 ], [ %23, %22 ]
%29 = add nsw i64 %28, -1
%30 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = icmp sgt i64 %28, 1
br i1 %33, label %27, label %34
34: ; preds = %27, %22, %16
%35 = tail call i32 @putchar(i32 10)
ret void
}