#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 */
scalar_t__ marshal_string(char *, size_t, char *, char **, size_t *);
scalar_t__ marshal_unsigned(char *, size_t, size_t, int, char **, size_t *);
int marshal_hex(char *buffer, size_t len, size_t hex_val, char **nbuffer,
                size_t *nlen) {
  int ret_val = 0;
  char *my_buffer;
  size_t my_len;
  ret_val += marshal_string(buffer, len, "0x", &my_buffer, &my_len);
  ret_val += marshal_unsigned(my_buffer, my_len, hex_val, 16, nbuffer, nlen);
  return ret_val;
}


x86 assembly (clang, -O0):
<marshal_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xeae(%rip),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x40(%rbp),%r8
call   1030 <marshal_string@plt>
mov    %rax,%rcx
movslq -0x2c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    $0x10,%ecx
call   1040 <marshal_unsigned@plt>
mov    %rax,%rcx
movslq -0x2c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<marshal_hex>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
lea    0xec5(%rip),%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1030 <marshal_string@plt>
mov    %rax,%rbx
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %r12,%rdx
mov    $0x10,%ecx
mov    %r15,%r8
mov    %r14,%r9
call   1040 <marshal_unsigned@plt>
add    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
define i32 @marshal_hex(i8* %0, i64 %1, i64 %2, i8** %3, i64* %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8**
%10 = alloca i64*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i8** %3, i8*** %9
store i64* %4, i64** %10
store i32 0, i32* %11
%14 = load i8*, i8** %6
%15 = load i64, i64* %7
%16 = call i64 @marshal_string(i8* %14, i64 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %12, i64* %13)
%17 = load i32, i32* %11
%18 = sext i32 %17 to i64
%19 = add nsw i64 %18, %16
%20 = trunc i64 %19 to i32
store i32 %20, i32* %11
%21 = load i8*, i8** %12
%22 = load i64, i64* %13
%23 = load i64, i64* %8
%24 = load i8**, i8*** %9
%25 = load i64*, i64** %10
%26 = call i64 @marshal_unsigned(i8* %21, i64 %22, i64 %23, i32 16, i8** %24, i64* %25)
%27 = load i32, i32* %11
%28 = sext i32 %27 to i64
%29 = add nsw i64 %28, %26
%30 = trunc i64 %29 to i32
store i32 %30, i32* %11
%31 = load i32, i32* %11
ret i32 %31
}

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
define i32 @marshal_hex(i8* %0, i64 %1, i64 %2, i8** %3, i64* %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = bitcast i8** %6 to i8*
%9 = bitcast i64* %7 to i8*
%10 = call i64 @marshal_string(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %6, i64* %7)
%11 = load i8*, i8** %6
%12 = load i64, i64* %7
%13 = call i64 @marshal_unsigned(i8* %11, i64 %12, i64 %2, i32 16, i8** %3, i64* %4)
%14 = add i64 %13, %10
%15 = trunc i64 %14 to i32
ret i32 %15
}