#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
void padded_octal(char *octal, int length, char *ppoctal) {
  char poctal[100];
  if (length > (int)strlen(octal)) {
    int i;
    for (i = 0; i < (length - (int)strlen(octal)); i++) {
      strcat(poctal, "0");
    }
  }
  strcat(poctal, octal);
  strcpy(ppoctal, poctal);
}


x86 assembly (clang, -O0):
<padded_octal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x88(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x88(%rbp),%eax
cmp    %ecx,%eax
jle    11d3 <padded_octal+0xa3>
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x90(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x90(%rbp),%ecx
mov    %rax,%rdx
mov    -0x8c(%rbp),%eax
sub    %edx,%ecx
cmp    %ecx,%eax
jge    11ce <padded_octal+0x9e>
lea    -0x80(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1173 <padded_octal+0x43>
jmp    11d3 <padded_octal+0xa3>
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<padded_octal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdx,%r14
mov    %esi,%r13d
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    %r13d,%eax
jge    118f <padded_octal+0x5f>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %r13d,%eax
jge    118f <padded_octal+0x5f>
xor    %ebp,%ebp
lea    0xe99(%rip),%r15
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r13d,%ecx
sub    %eax,%ecx
cmp    %ecx,%ebp
jl     1170 <padded_octal+0x40>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
define void @padded_octal(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [100 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i32, i32* %5
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
%12 = trunc i64 %11 to i32
%13 = icmp sgt i32 %9, %12
br i1 %13, label %14, label %30
14: ; preds = %3
store i32 0, i32* %8
br label %15
15: ; preds = %26, %14
%16 = load i32, i32* %8
%17 = load i32, i32* %5
%18 = load i8*, i8** %4
%19 = call i64 @strlen(i8* %18)
%20 = trunc i64 %19 to i32
%21 = sub nsw i32 %17, %20
%22 = icmp slt i32 %16, %21
br i1 %22, label %23, label %29
23: ; preds = %15
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %23
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %15
29: ; preds = %15
br label %30
30: ; preds = %29, %3
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%32 = load i8*, i8** %4
%33 = call i32 @strcat(i8* %31, i8* %32)
%34 = load i8*, i8** %6
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%36 = call i32 @strcpy(i8* %34, i8* %35)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
define void @padded_octal(i8* %0, i32 %1, i8* %2) {
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = trunc i64 %6 to i32
%8 = icmp slt i32 %7, %1
br i1 %8, label %9, label %21
9: ; preds = %3
%10 = call i64 @strlen(i8* dereferenceable(1) %0)
%11 = trunc i64 %10 to i32
%12 = icmp slt i32 %11, %1
br i1 %12, label %13, label %21
13: ; preds = %9, %13
%14 = phi i32 [ %16, %13 ], [ 0, %9 ]
%15 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = add nuw nsw i32 %14, 1
%17 = call i64 @strlen(i8* dereferenceable(1) %0)
%18 = trunc i64 %17 to i32
%19 = sub nsw i32 %1, %18
%20 = icmp slt i32 %16, %19
br i1 %20, label %13, label %21
21: ; preds = %13, %9, %3
%22 = call i32 @strcat(i8* %5, i8* %0)
%23 = call i32 @strcpy(i8* %2, i8* %5)
ret void
}