#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*/ sprintf(char *, char *, int);
char *strdup(char *);
char *translate_decimal(char *source) {
  char buffer[2048];
  char *ptr = buffer;
  *ptr = '\0';
  while (*source) {
    ptr += sprintf(ptr, " %02d", (int)*source);
    source++;
  }
  return strdup(buffer);
}


x86 assembly (clang, -O0):
<translate_decimal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x818(%rbp)
mov    -0x818(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1195 <translate_decimal+0x75>
mov    -0x818(%rbp),%rdi
mov    -0x8(%rbp),%rax
movsbl (%rax),%edx
lea    0xe97(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x818(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x818(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1147 <translate_decimal+0x27>
lea    -0x810(%rbp),%rdi
call   1040 <strdup@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<translate_decimal>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
movb   $0x0,(%rsp)
mov    (%rdi),%al
test   %al,%al
je     116f <translate_decimal+0x4f>
mov    %rdi,%r14
mov    %rsp,%rbx
add    $0x1,%r14
lea    0xeb9(%rip),%r15
nopw   0x0(%rax,%rax,1)
movsbl %al,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <sprintf@plt>
cltq
add    %rax,%rbx
movzbl (%r14),%eax
add    $0x1,%r14
test   %al,%al
jne    1150 <translate_decimal+0x30>
mov    %rsp,%rdi
call   1040 <strdup@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c" %02d\00"
define i8* @translate_decimal(i8* %0) {
%2 = alloca i8*
%3 = alloca [2048 x i8]
%4 = alloca i8*
store i8* %0, i8** %2
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
store i8* %5, i8** %4
%6 = load i8*, i8** %4
store i8 0, i8* %6
br label %7
7: ; preds = %11, %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = load i8*, i8** %2
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i8*, i8** %4
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds i8, i8* %17, i64 %18
store i8* %19, i8** %4
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %2
br label %7
22: ; preds = %7
%23 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%24 = call i8* @strdup(i8* %23)
ret i8* %24
}

LLVM IR (-O2):
@.str = [6 x i8] c" %02d\00"
define noalias i8* @translate_decimal(i8* nocapture %0) {
%2 = alloca [2048 x i8]
%3 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
store i8 0, i8* %3
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %1, %6
%7 = phi i8 [ %15, %6 ], [ %4, %1 ]
%8 = phi i8* [ %13, %6 ], [ %3, %1 ]
%9 = phi i8* [ %14, %6 ], [ %0, %1 ]
%10 = sext i8 %7 to i32
%11 = call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %8, i64 %12
%14 = getelementptr inbounds i8, i8* %9, i64 1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %6
17: ; preds = %6, %1
%18 = call i8* @strdup(i8* %3)
ret i8* %18
}