#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 */
char *stradd(char *, char *);
void ntohex(int nb, char *out) {
  unsigned int i;
  char sym[] = "0123456789ABCDEF";
  out = stradd(out, "0x");
  for (i = 0; i < 8; i++) {
    *(out++) = sym[(nb >> ((7 - i) << 2)) & 0xf];
  }
  *out = 0xa;
}


x86 assembly (clang, -O0):
<ntohex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xed5(%rip),%al
mov    %al,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec8(%rip),%rsi
call   1030 <stradd@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jae    119b <ntohex+0x8b>
mov    -0x4(%rbp),%eax
mov    $0x7,%ecx
sub    -0x14(%rbp),%ecx
shl    $0x2,%ecx
sar    %cl,%eax
and    $0xf,%eax
cltq
mov    -0x30(%rbp,%rax,1),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1159 <ntohex+0x49>
mov    -0x10(%rbp),%rax
movb   $0xa,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ntohex>:
push   %rbx
mov    %rsi,%rax
mov    %edi,%ebx
lea    0xef4(%rip),%rsi
mov    %rax,%rdi
call   1030 <stradd@plt>
mov    %ebx,%ecx
mov    %rcx,%rsi
shr    $0x1c,%rsi
lea    0xecb(%rip),%rdi
mov    (%rsi,%rdi,1),%dl
mov    %dl,(%rax)
mov    %ebx,%edx
shr    $0x18,%edx
and    $0xf,%edx
mov    (%rdx,%rdi,1),%dl
mov    %dl,0x1(%rax)
mov    %ebx,%edx
shr    $0x14,%edx
and    $0xf,%edx
mov    (%rdx,%rdi,1),%dl
mov    %dl,0x2(%rax)
mov    %ebx,%edx
shr    $0x10,%edx
and    $0xf,%edx
mov    (%rdx,%rdi,1),%dl
mov    %dl,0x3(%rax)
mov    %ebx,%edx
shr    $0xc,%edx
and    $0xf,%edx
mov    (%rdx,%rdi,1),%dl
mov    %dl,0x4(%rax)
mov    %ebx,%edx
shr    $0x8,%edx
and    $0xf,%edx
mov    (%rdx,%rdi,1),%dl
mov    %dl,0x5(%rax)
shr    $0x4,%ebx
and    $0xf,%ebx
mov    (%rbx,%rdi,1),%dl
mov    %dl,0x6(%rax)
and    $0xf,%ecx
mov    (%rcx,%rdi,1),%cl
mov    %cl,0x7(%rax)
movb   $0xa,0x8(%rax)
pop    %rbx
ret

LLVM IR (-O0):
@__const.ntohex.sym = [17 x i8] c"0123456789ABCDEF\00"
@.str = [3 x i8] c"0x\00"
define void @ntohex(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [17 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = bitcast [17 x i8]* %6 to i8*
%8 = load i8*, i8** %4
%9 = call i8* @stradd(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %4
store i32 0, i32* %5
br label %10
10: ; preds = %25, %2
%11 = load i32, i32* %5
%12 = icmp ult i32 %11, 8
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = load i32, i32* %3
%15 = load i32, i32* %5
%16 = sub i32 7, %15
%17 = shl i32 %16, 2
%18 = ashr i32 %14, %17
%19 = and i32 %18, 15
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
store i8 %22, i8* %23
br label %25
25: ; preds = %13
%26 = load i32, i32* %5
%27 = add i32 %26, 1
store i32 %27, i32* %5
br label %10
28: ; preds = %10
%29 = load i8*, i8** %4
store i8 10, i8* %29
ret void
}

LLVM IR (-O2):
@__const.ntohex.sym = [17 x i8] c"0123456789ABCDEF\00"
@.str = [3 x i8] c"0x\00"
define void @ntohex(i32 %0, i8* %1) {
%3 = tail call i8* @stradd(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = lshr i32 %0, 28
%5 = zext i32 %4 to i64
%6 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.ntohex.sym, i64 0, i64 %5
%7 = load i8, i8* %6
%8 = getelementptr inbounds i8, i8* %3, i64 1
store i8 %7, i8* %3
%9 = lshr i32 %0, 24
%10 = and i32 %9, 15
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.ntohex.sym, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %3, i64 2
store i8 %13, i8* %8
%15 = lshr i32 %0, 20
%16 = and i32 %15, 15
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.ntohex.sym, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = getelementptr inbounds i8, i8* %3, i64 3
store i8 %19, i8* %14
%21 = lshr i32 %0, 16
%22 = and i32 %21, 15
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.ntohex.sym, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = getelementptr inbounds i8, i8* %3, i64 4
store i8 %25, i8* %20
%27 = lshr i32 %0, 12
%28 = and i32 %27, 15
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.ntohex.sym, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = getelementptr inbounds i8, i8* %3, i64 5
store i8 %31, i8* %26
%33 = lshr i32 %0, 8
%34 = and i32 %33, 15
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.ntohex.sym, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = getelementptr inbounds i8, i8* %3, i64 6
store i8 %37, i8* %32
%39 = lshr i32 %0, 4
%40 = and i32 %39, 15
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.ntohex.sym, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = getelementptr inbounds i8, i8* %3, i64 7
store i8 %43, i8* %38
%45 = and i32 %0, 15
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.ntohex.sym, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = getelementptr inbounds i8, i8* %3, i64 8
store i8 %48, i8* %44
store i8 10, i8* %49
ret void
}