#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 getDebug();
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
int strlen(char *);
void convert(char *str, int c) {
  int i;
  if (getDebug() > 2)
    printf("I: HEX to string: %X\n", c);
  sprintf(str, "%X", c);
  if (strlen(str) == 1) {
    str[1] = str[0];
    str[0] = '0';
    str[2] = '\0';
  }
  if (getDebug() > 2)
    for (i = 0; i < strlen(str); i++)
      printf("   * char %d = %d\n", i, str[i]);
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getDebug@plt>
cmp    $0x2,%eax
jle    1170 <convert+0x30>
mov    -0xc(%rbp),%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe98(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jne    11b1 <convert+0x71>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x8(%rbp),%rax
movb   $0x30,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    $0x0,%al
call   1050 <getDebug@plt>
cmp    $0x2,%eax
jle    1214 <convert+0xd4>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    120f <convert+0xcf>
mov    -0x10(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11c8 <convert+0x88>
jmp    1214 <convert+0xd4>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <getDebug@plt>
cmp    $0x3,%eax
jl     1165 <convert+0x25>
lea    0xea4(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeaa(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jne    118f <convert+0x4f>
mov    (%rbx),%al
mov    %al,0x1(%rbx)
movb   $0x30,(%rbx)
movb   $0x0,0x2(%rbx)
xor    %eax,%eax
call   1050 <getDebug@plt>
cmp    $0x3,%eax
jl     11d3 <convert+0x93>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11d3 <convert+0x93>
lea    0xe6b(%rip),%r14
xor    %ebp,%ebp
movsbl (%rbx,%rbp,1),%edx
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     11b0 <convert+0x70>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"I: HEX to string: %X\0A\00"
@.str.1 = [3 x i8] c"%X\00"
@.str.2 = [19 x i8] c" * char %d = %d\0A\00"
define void @convert(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = call i32 (...) @getDebug()
%7 = icmp sgt i32 %6, 2
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* %4
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %8, %2
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %28
18: ; preds = %11
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 %21, i8* %23
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 0
store i8 48, i8* %25
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 2
store i8 0, i8* %27
br label %28
28: ; preds = %18, %11
%29 = call i32 (...) @getDebug()
%30 = icmp sgt i32 %29, 2
br i1 %30, label %31, label %50
31: ; preds = %28
store i32 0, i32* %5
br label %32
32: ; preds = %46, %31
%33 = load i32, i32* %5
%34 = load i8*, i8** %3
%35 = call i32 @strlen(i8* %34)
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %49
37: ; preds = %32
%38 = load i32, i32* %5
%39 = load i8*, i8** %3
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %38, i32 %44)
br label %46
46: ; preds = %37
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
store i32 %48, i32* %5
br label %32
49: ; preds = %32
br label %50
50: ; preds = %49, %28
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"I: HEX to string: %X\0A\00"
@.str.1 = [3 x i8] c"%X\00"
@.str.2 = [19 x i8] c" * char %d = %d\0A\00"
define void @convert(i8* %0, i32 %1) {
%3 = tail call i32 (...) @getDebug()
%4 = icmp sgt i32 %3, 2
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %7
7: ; preds = %5, %2
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%9 = tail call i32 @strlen(i8* %0)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i8, i8* %0
%13 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %12, i8* %13
store i8 48, i8* %0
%14 = getelementptr inbounds i8, i8* %0, i64 2
store i8 0, i8* %14
br label %15
15: ; preds = %11, %7
%16 = tail call i32 (...) @getDebug()
%17 = icmp sgt i32 %16, 2
br i1 %17, label %18, label %32
18: ; preds = %15
%19 = tail call i32 @strlen(i8* %0)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %18, %21
%22 = phi i64 [ %28, %21 ], [ 0, %18 ]
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = trunc i64 %22 to i32
%27 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %25)
%28 = add nuw nsw i64 %22, 1
%29 = tail call i32 @strlen(i8* %0)
%30 = sext i32 %29 to i64
%31 = icmp slt i64 %28, %30
br i1 %31, label %21, label %32
32: ; preds = %21, %18, %15
ret void
}