#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);
void int_to_hexstr(int i, char *str) {
  sprintf(str, "%2x", i);
  for (i = 0; i < 2; i++)
    if (str[i] == ' ')
      str[i] = '0';
}


x86 assembly (clang, -O0):
<int_to_hexstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xed3(%rip),%rsi
call   1030 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    1177 <int_to_hexstr+0x67>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1164 <int_to_hexstr+0x54>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
jmp    1169 <int_to_hexstr+0x59>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1139 <int_to_hexstr+0x29>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_to_hexstr>:
push   %rbx
mov    %rsi,%rbx
mov    %edi,%edx
lea    0xee3(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
cmpb   $0x20,(%rbx)
je     1132 <int_to_hexstr+0x22>
cmpb   $0x20,0x1(%rbx)
je     113b <int_to_hexstr+0x2b>
pop    %rbx
ret
movb   $0x30,(%rbx)
cmpb   $0x20,0x1(%rbx)
jne    1130 <int_to_hexstr+0x20>
movb   $0x30,0x1(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%2x\00"
define void @int_to_hexstr(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = load i32, i32* %3
%7 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 0, i32* %3
br label %8
8: ; preds = %25, %2
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = load i8*, i8** %4
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 32
br i1 %18, label %19, label %24
19: ; preds = %11
%20 = load i8*, i8** %4
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 48, i8* %23
br label %24
24: ; preds = %19, %11
br label %25
25: ; preds = %24
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %8
28: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%2x\00"
define void @int_to_hexstr(i32 %0, i8* nocapture %1) {
%3 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 32
br i1 %5, label %6, label %7
6: ; preds = %2
store i8 48, i8* %1
br label %7
7: ; preds = %2, %6
%8 = getelementptr inbounds i8, i8* %1, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 32
br i1 %10, label %11, label %12
11: ; preds = %7
store i8 48, i8* %8
br label %12
12: ; preds = %11, %7
ret void
}