#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*/ _sys_write(char *, int);
void print_hex(unsigned int nr) {
  char kc_hex_chars[16];
  int j = 0;
  int i;
  for (i = 0; i < 10; i++)
    kc_hex_chars[i] = '0' + i;
  for (i = 10; i < 16; i++)
    kc_hex_chars[i] = 'A' + i - 10;
  _sys_write("0", 1);
  _sys_write("x", 1);
  if (nr == 0) {
    _sys_write("0", 1);
    return;
  }
  for (i = 7; i >= 0; i--) {
    unsigned int tmp = (nr >> (i * 4)) & 0xF;
    if (j == 0 && tmp != 0)
      j = 1;
    if (j != 0)
      _sys_write(&(kc_hex_chars[tmp]), 1);
  }
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0xa,-0x28(%rbp)
jge    1151 <print_hex+0x41>
mov    -0x28(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
movslq -0x28(%rbp),%rax
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1129 <print_hex+0x19>
movl   $0xa,-0x28(%rbp)
cmpl   $0x10,-0x28(%rbp)
jge    1183 <print_hex+0x73>
mov    -0x28(%rbp),%eax
add    $0x41,%eax
sub    $0xa,%eax
mov    %al,%cl
movslq -0x28(%rbp),%rax
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1158 <print_hex+0x48>
lea    0xe76(%rip),%rdi
mov    $0x1,%esi
call   1030 <_sys_write@plt>
lea    0xe67(%rip),%rdi
mov    $0x1,%esi
call   1030 <_sys_write@plt>
cmpl   $0x0,-0x4(%rbp)
jne    11c5 <print_hex+0xb5>
lea    0xe4a(%rip),%rdi
mov    $0x1,%esi
call   1030 <_sys_write@plt>
jmp    1233 <print_hex+0x123>
movl   $0x7,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     1233 <print_hex+0x123>
mov    -0x4(%rbp),%eax
mov    -0x28(%rbp),%ecx
shl    $0x2,%ecx
shr    %cl,%eax
and    $0xf,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1202 <print_hex+0xf2>
cmpl   $0x0,-0x2c(%rbp)
je     1202 <print_hex+0xf2>
movl   $0x1,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1220 <print_hex+0x110>
mov    -0x2c(%rbp),%eax
lea    -0x20(%rbp),%rdi
add    %rax,%rdi
mov    $0x1,%esi
call   1030 <_sys_write@plt>
jmp    1225 <print_hex+0x115>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    11cc <print_hex+0xbc>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movaps 0xee2(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xee7(%rip),%rdi
mov    $0x1,%esi
call   1030 <_sys_write@plt>
lea    0xed8(%rip),%rdi
mov    $0x1,%esi
call   1030 <_sys_write@plt>
test   %ebx,%ebx
je     116d <print_hex+0x5d>
cmp    $0xfffffff,%ebx
jbe    1183 <print_hex+0x73>
mov    %ebx,%eax
shr    $0x1c,%eax
lea    (%rsp,%rax,1),%rdi
mov    $0x1,%esi
call   1030 <_sys_write@plt>
mov    %ebx,%eax
shr    $0x18,%eax
and    $0xf,%eax
jmp    1194 <print_hex+0x84>
lea    0xe9c(%rip),%rdi
mov    $0x1,%esi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <_sys_write@plt>
mov    %ebx,%eax
cmp    $0x1000000,%ebx
jb     1235 <print_hex+0x125>
shr    $0x18,%eax
mov    %eax,%eax
lea    (%rsp,%rax,1),%rdi
mov    $0x1,%esi
call   1030 <_sys_write@plt>
mov    %ebx,%eax
shr    $0x14,%eax
and    $0xf,%eax
mov    %eax,%eax
lea    (%rsp,%rax,1),%rdi
mov    $0x1,%esi
call   1030 <_sys_write@plt>
mov    %ebx,%eax
shr    $0x10,%eax
and    $0xf,%eax
mov    %eax,%eax
lea    (%rsp,%rax,1),%rdi
mov    $0x1,%esi
call   1030 <_sys_write@plt>
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
mov    %eax,%eax
lea    (%rsp,%rax,1),%rdi
mov    $0x1,%esi
call   1030 <_sys_write@plt>
mov    %ebx,%eax
shr    $0x8,%eax
and    $0xf,%eax
mov    %eax,%eax
lea    (%rsp,%rax,1),%rdi
mov    $0x1,%esi
call   1030 <_sys_write@plt>
mov    %ebx,%eax
shr    $0x4,%eax
and    $0xf,%eax
mov    %eax,%eax
lea    (%rsp,%rax,1),%rdi
mov    $0x1,%esi
call   1030 <_sys_write@plt>
and    $0xf,%ebx
mov    %ebx,%eax
lea    (%rsp,%rax,1),%rdi
mov    $0x1,%esi
call   1030 <_sys_write@plt>
add    $0x10,%rsp
pop    %rbx
ret
shr    $0x14,%eax
and    $0xf,%eax
jne    11ac <print_hex+0x9c>
mov    %ebx,%eax
shr    $0x10,%eax
and    $0xf,%eax
jne    11c4 <print_hex+0xb4>
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
jne    11dc <print_hex+0xcc>
mov    %ebx,%eax
shr    $0x8,%eax
and    $0xf,%eax
jne    11f4 <print_hex+0xe4>
mov    %ebx,%eax
shr    $0x4,%eax
and    $0xf,%eax
jne    120c <print_hex+0xfc>
and    $0xf,%ebx
jne    121f <print_hex+0x10f>
jmp    122f <print_hex+0x11f>

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@.str.1 = [2 x i8] c"x\00"
define void @print_hex(i32 %0) {
%2 = alloca i32
%3 = alloca [16 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %17, %1
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = load i32, i32* %5
%12 = add nsw i32 48, %11
%13 = trunc i32 %12 to i8
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %15
store i8 %13, i8* %16
br label %17
17: ; preds = %10
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
br label %7
20: ; preds = %7
store i32 10, i32* %5
br label %21
21: ; preds = %32, %20
%22 = load i32, i32* %5
%23 = icmp slt i32 %22, 16
br i1 %23, label %24, label %35
24: ; preds = %21
%25 = load i32, i32* %5
%26 = add nsw i32 65, %25
%27 = sub nsw i32 %26, 10
%28 = trunc i32 %27 to i8
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %30
store i8 %28, i8* %31
br label %32
32: ; preds = %24
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %21
35: ; preds = %21
%36 = call i32 @_sys_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%37 = call i32 @_sys_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%38 = load i32, i32* %2
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @_sys_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %70
42: ; preds = %35
store i32 7, i32* %5
br label %43
43: ; preds = %67, %42
%44 = load i32, i32* %5
%45 = icmp sge i32 %44, 0
br i1 %45, label %46, label %70
46: ; preds = %43
%47 = load i32, i32* %2
%48 = load i32, i32* %5
%49 = mul nsw i32 %48, 4
%50 = lshr i32 %47, %49
%51 = and i32 %50, 15
store i32 %51, i32* %6
%52 = load i32, i32* %4
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %46
%55 = load i32, i32* %6
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %54
store i32 1, i32* %4
br label %58
58: ; preds = %57, %54, %46
%59 = load i32, i32* %4
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %58
%62 = load i32, i32* %6
%63 = zext i32 %62 to i64
%64 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %63
%65 = call i32 @_sys_write(i8* %64, i32 1)
br label %66
66: ; preds = %61, %58
br label %67
67: ; preds = %66
%68 = load i32, i32* %5
%69 = add nsw i32 %68, -1
store i32 %69, i32* %5
br label %43
70: ; preds = %40, %43
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
@.str.1 = [2 x i8] c"x\00"
define void @print_hex(i32 %0) {
%2 = alloca <16 x i8>
%3 = getelementptr inbounds <16 x i8>, <16 x i8>* %2, i64 0, i64 0
store <16 x i8> <i8 48, i8 49, i8 50, i8 51, i8 52, i8 53, i8 54, i8 55, i8 56, i8 57, i8 65, i8 66, i8 67, i8 68, i8 69, i8 70>, <16 x i8>* %2
%4 = tail call i32 @_sys_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%5 = tail call i32 @_sys_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%6 = icmp eq i32 %0, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = icmp ugt i32 %0, 268435455
br i1 %8, label %11, label %18
9: ; preds = %1
%10 = tail call i32 @_sys_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %90
11: ; preds = %7
%12 = lshr i32 %0, 28
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds <16 x i8>, <16 x i8>* %2, i64 0, i64 %13
%15 = call i32 @_sys_write(i8* %14, i32 1)
%16 = lshr i32 %0, 24
%17 = and i32 %16, 15
br label %21
18: ; preds = %7
%19 = lshr i32 %0, 24
%20 = icmp ugt i32 %0, 16777215
br i1 %20, label %21, label %28
21: ; preds = %18, %11
%22 = phi i32 [ %17, %11 ], [ %19, %18 ]
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds <16 x i8>, <16 x i8>* %2, i64 0, i64 %23
%25 = call i32 @_sys_write(i8* %24, i32 1)
%26 = lshr i32 %0, 20
%27 = and i32 %26, 15
br label %32
28: ; preds = %18
%29 = lshr i32 %0, 20
%30 = and i32 %29, 15
%31 = icmp eq i32 %30, 0
br i1 %31, label %39, label %32
32: ; preds = %28, %21
%33 = phi i32 [ %27, %21 ], [ %30, %28 ]
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds <16 x i8>, <16 x i8>* %2, i64 0, i64 %34
%36 = call i32 @_sys_write(i8* %35, i32 1)
%37 = lshr i32 %0, 16
%38 = and i32 %37, 15
br label %43
39: ; preds = %28
%40 = lshr i32 %0, 16
%41 = and i32 %40, 15
%42 = icmp eq i32 %41, 0
br i1 %42, label %50, label %43
43: ; preds = %39, %32
%44 = phi i32 [ %38, %32 ], [ %41, %39 ]
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds <16 x i8>, <16 x i8>* %2, i64 0, i64 %45
%47 = call i32 @_sys_write(i8* %46, i32 1)
%48 = lshr i32 %0, 12
%49 = and i32 %48, 15
br label %54
50: ; preds = %39
%51 = lshr i32 %0, 12
%52 = and i32 %51, 15
%53 = icmp eq i32 %52, 0
br i1 %53, label %61, label %54
54: ; preds = %50, %43
%55 = phi i32 [ %49, %43 ], [ %52, %50 ]
%56 = zext i32 %55 to i64
%57 = getelementptr inbounds <16 x i8>, <16 x i8>* %2, i64 0, i64 %56
%58 = call i32 @_sys_write(i8* %57, i32 1)
%59 = lshr i32 %0, 8
%60 = and i32 %59, 15
br label %65
61: ; preds = %50
%62 = lshr i32 %0, 8
%63 = and i32 %62, 15
%64 = icmp eq i32 %63, 0
br i1 %64, label %72, label %65
65: ; preds = %61, %54
%66 = phi i32 [ %60, %54 ], [ %63, %61 ]
%67 = zext i32 %66 to i64
%68 = getelementptr inbounds <16 x i8>, <16 x i8>* %2, i64 0, i64 %67
%69 = call i32 @_sys_write(i8* %68, i32 1)
%70 = lshr i32 %0, 4
%71 = and i32 %70, 15
br label %76
72: ; preds = %61
%73 = lshr i32 %0, 4
%74 = and i32 %73, 15
%75 = icmp eq i32 %74, 0
br i1 %75, label %82, label %76
76: ; preds = %72, %65
%77 = phi i32 [ %71, %65 ], [ %74, %72 ]
%78 = zext i32 %77 to i64
%79 = getelementptr inbounds <16 x i8>, <16 x i8>* %2, i64 0, i64 %78
%80 = call i32 @_sys_write(i8* %79, i32 1)
%81 = and i32 %0, 15
br label %85
82: ; preds = %72
%83 = and i32 %0, 15
%84 = icmp eq i32 %83, 0
br i1 %84, label %90, label %85
85: ; preds = %76, %82
%86 = phi i32 [ %81, %76 ], [ %83, %82 ]
%87 = zext i32 %86 to i64
%88 = getelementptr inbounds <16 x i8>, <16 x i8>* %2, i64 0, i64 %87
%89 = call i32 @_sys_write(i8* %88, i32 1)
br label %90
90: ; preds = %82, %85, %9
ret void
}