#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);
int strlen(char *);
int /*<<< orphan*/ uCharToHex(unsigned char *, unsigned char *, int);
int int_to_hex_2(int num, unsigned char *hex_len) {
  unsigned char char_len[4] = {'\0'};
  int hex_num = 0;
  hex_num = num / 10 * 16 + num % 10;
  sprintf((char *)char_len, "%02x", hex_num);
  uCharToHex(char_len, hex_len, 2);
  return (strlen((char *)(hex_len)));
}


x86 assembly (clang, -O0):
<int_to_hex_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x18(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe68(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x14(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2,%edx
call   1050 <uCharToHex@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_to_hex_2>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
movl   $0x0,0x4(%rsp)
movslq %edi,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
mov    %eax,%ecx
shl    $0x4,%ecx
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
add    %ecx,%edx
lea    0xe95(%rip),%rsi
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1040 <uCharToHex@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
define i32 @int_to_hex_2(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [4 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = bitcast [4 x i8]* %5 to i8*
store i32 0, i32* %6
%8 = load i32, i32* %3
%9 = sdiv i32 %8, 10
%10 = mul nsw i32 %9, 16
%11 = load i32, i32* %3
%12 = srem i32 %11, 10
%13 = add nsw i32 %10, %12
store i32 %13, i32* %6
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%15 = load i32, i32* %6
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%18 = load i8*, i8** %4
%19 = call i32 @uCharToHex(i8* %17, i8* %18, i32 2)
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
ret i32 %21
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
define i32 @int_to_hex_2(i32 %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = sdiv i32 %0, 10
%6 = shl nsw i32 %5, 4
%7 = srem i32 %0, 10
%8 = add nsw i32 %6, %7
%9 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @uCharToHex(i8* %4, i8* %1, i32 2)
%11 = call i32 @strlen(i8* %1)
ret i32 %11
}