#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 */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int _to_x(char *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ _uc(char *);
int _to_hex(char *buf, uint32_t value, int alt_form, int precision,
            int prefix) {
  int len;
  char *buf0 = buf;
  if (alt_form) {
    *buf++ = '0';
    *buf++ = 'x';
  }
  len = _to_x(buf, value, 16, precision);
  if (prefix == 'X') {
    _uc(buf0);
  }
  return len + (buf - buf0);
}


x86 assembly (clang, -O0):
<_to_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     116f <_to_hex+0x4f>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x30,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x78,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%ecx
mov    $0x10,%edx
call   1030 <_to_x@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x58,-0x18(%rbp)
jne    1199 <_to_hex+0x79>
mov    -0x28(%rbp),%rdi
call   1040 <_uc@plt>
movslq -0x1c(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x28(%rbp),%rdx
sub    %rdx,%rcx
add    %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_to_hex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %rdi,%r14
mov    %rdi,%rbx
test   %edx,%edx
je     113e <_to_hex+0x1e>
movw   $0x7830,(%r14)
lea    0x2(%r14),%rbx
mov    %rbx,%rdi
mov    $0x10,%edx
call   1030 <_to_x@plt>
mov    %eax,%ebp
cmp    $0x58,%r15d
jne    115b <_to_hex+0x3b>
mov    %r14,%rdi
call   1040 <_uc@plt>
sub    %r14d,%ebx
add    %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_to_hex(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = load i8*, i8** %6
store i8* %13, i8** %12
%14 = load i32, i32* %8
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %5
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %6
store i8 48, i8* %17
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %6
store i8 120, i8* %19
br label %21
21: ; preds = %16, %5
%22 = load i8*, i8** %6
%23 = load i32, i32* %7
%24 = load i32, i32* %9
%25 = call i32 @_to_x(i8* %22, i32 %23, i32 16, i32 %24)
store i32 %25, i32* %11
%26 = load i32, i32* %10
%27 = icmp eq i32 %26, 88
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load i8*, i8** %12
%30 = call i32 @_uc(i8* %29)
br label %31
31: ; preds = %28, %21
%32 = load i32, i32* %11
%33 = sext i32 %32 to i64
%34 = load i8*, i8** %6
%35 = load i8*, i8** %12
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = add nsw i64 %33, %38
%40 = trunc i64 %39 to i32
ret i32 %40
}

LLVM IR (-O2):
define i32 @_to_hex(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp eq i32 %2, 0
br i1 %6, label %10, label %7
7: ; preds = %5
%8 = getelementptr inbounds i8, i8* %0, i64 1
store i8 48, i8* %0
%9 = getelementptr inbounds i8, i8* %0, i64 2
store i8 120, i8* %8
br label %10
10: ; preds = %7, %5
%11 = phi i8* [ %9, %7 ], [ %0, %5 ]
%12 = tail call i32 @_to_x(i8* %11, i32 %1, i32 16, i32 %3)
%13 = icmp eq i32 %4, 88
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @_uc(i8* %0)
br label %16
16: ; preds = %14, %10
%17 = ptrtoint i8* %11 to i64
%18 = ptrtoint i8* %0 to i64
%19 = sub i64 %17, %18
%20 = trunc i64 %19 to i32
%21 = add i32 %12, %20
ret i32 %21
}