#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 uint32_t;
typedef int int32_t;

/* Variables and functions */
int32_t convert_hex32(uint32_t x, char *int_buffer, char **out_pointer) {
  int int_pointer;
  int printed_size = 0;
  int_pointer = 31;
  int_buffer[int_pointer] = '\0';
  int_pointer--;
  do {
    if ((x % 16) < 10) {
      int_buffer[int_pointer] = (x % 16) + '0';
    } else {
      int_buffer[int_pointer] = (x % 16) - 10 + 'a';
    }
    int_pointer--;
    printed_size++;
    x /= 16;
  } while (x != 0);
  *out_pointer = &int_buffer[int_pointer + 1];
  return printed_size;
}


x86 assembly (clang, -O0):
<convert_hex32>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x1f,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xa,%edx
jge    1164 <convert_hex32+0x64>
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1184 <convert_hex32+0x84>
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
sub    $0xa,%eax
add    $0x61,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1132 <convert_hex32+0x32>
mov    -0x10(%rbp),%rcx
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_hex32>:
push   %rbx
movb   $0x0,0x1f(%rsi)
movabs $0x1f00000000,%r11
xor    %eax,%eax
mov    $0x30,%r8d
movabs $0xffffffff00000000,%r9
ff ff ff
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xf(%rdi),%r10d
test   %edi,%edi
mov    %edi,%ecx
cmovs  %r10d,%ecx
mov    %ecx,%ebx
and    $0xfffffff0,%ebx
sub    %ebx,%edi
cmp    $0xa,%edi
mov    $0x57,%ebx
cmovl  %r8d,%ebx
add    %dil,%bl
mov    %bl,0x1e(%rsi,%rax,1)
sar    $0x4,%ecx
add    %r9,%r11
add    $0xffffffffffffffff,%rax
mov    %ecx,%edi
cmp    $0x1e,%r10d
ja     1130 <convert_hex32+0x30>
sar    $0x20,%r11
add    %r11,%rsi
mov    %rsi,(%rdx)
neg    %eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @convert_hex32(i32 %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8** %2, i8*** %6
store i32 0, i32* %8
store i32 31, i32* %7
%9 = load i8*, i8** %5
%10 = load i32, i32* %7
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
store i8 0, i8* %12
%13 = load i32, i32* %7
%14 = add nsw i32 %13, -1
store i32 %14, i32* %7
br label %15
15: ; preds = %45, %3
%16 = load i32, i32* %4
%17 = srem i32 %16, 16
%18 = icmp slt i32 %17, 10
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i32, i32* %4
%21 = srem i32 %20, 16
%22 = add nsw i32 %21, 48
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %5
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 %23, i8* %27
br label %38
28: ; preds = %15
%29 = load i32, i32* %4
%30 = srem i32 %29, 16
%31 = sub nsw i32 %30, 10
%32 = add nsw i32 %31, 97
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %5
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 %33, i8* %37
br label %38
38: ; preds = %28, %19
%39 = load i32, i32* %7
%40 = add nsw i32 %39, -1
store i32 %40, i32* %7
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
%43 = load i32, i32* %4
%44 = sdiv i32 %43, 16
store i32 %44, i32* %4
br label %45
45: ; preds = %38
%46 = load i32, i32* %4
%47 = icmp ne i32 %46, 0
br i1 %47, label %15, label %48
48: ; preds = %45
%49 = load i8*, i8** %5
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %49, i64 %52
%54 = load i8**, i8*** %6
store i8* %53, i8** %54
%55 = load i32, i32* %8
ret i32 %55
}

LLVM IR (-O2):
define i32 @convert_hex32(i32 %0, i8* %1, i8** nocapture writeonly %2) {
%4 = getelementptr inbounds i8, i8* %1, i64 31
store i8 0, i8* %4
br label %5
5: ; preds = %5, %3
%6 = phi i64 [ %15, %5 ], [ 30, %3 ]
%7 = phi i32 [ %17, %5 ], [ %0, %3 ]
%8 = phi i32 [ %16, %5 ], [ 0, %3 ]
%9 = srem i32 %7, 16
%10 = icmp slt i32 %9, 10
%11 = trunc i32 %9 to i8
%12 = select i1 %10, i8 48, i8 87
%13 = add nsw i8 %12, %11
%14 = getelementptr inbounds i8, i8* %1, i64 %6
store i8 %13, i8* %14
%15 = add i64 %6, -1
%16 = add nuw nsw i32 %8, 1
%17 = sdiv i32 %7, 16
%18 = add i32 %7, 15
%19 = icmp ult i32 %18, 31
br i1 %19, label %20, label %5
20: ; preds = %5
%21 = shl i64 %6, 32
%22 = ashr exact i64 %21, 32
%23 = getelementptr inbounds i8, i8* %1, i64 %22
store i8* %23, i8** %2
ret i32 %16
}