#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void put_hexw(unsigned int value, FILE *fout) {
  char stack[10];
  unsigned int i, j;
  i = 0;
  j = 4;
  do {
    stack[i] = (value % 16) + '0';
    if (stack[i] > 0x39)
      stack[i] += 7;
    i++;
  } while (value /= 16);
  while (i < j--) {
    fputc('0', fout);
  }
  while (i) {
    fputc(stack[--i], fout);
  }
}


x86 assembly (clang, -O0):
<put_hexw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x4,-0x24(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf,%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x20(%rbp),%eax
mov    %cl,-0x1a(%rbp,%rax,1)
mov    -0x20(%rbp),%eax
movsbl -0x1a(%rbp,%rax,1),%eax
cmp    $0x39,%eax
jle    115f <put_hexw+0x4f>
mov    -0x20(%rbp),%eax
movsbl -0x1a(%rbp,%rax,1),%ecx
add    $0x7,%ecx
mov    %cl,-0x1a(%rbp,%rax,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jne    112d <put_hexw+0x1d>
jmp    117f <put_hexw+0x6f>
mov    -0x20(%rbp),%eax
mov    -0x24(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x24(%rbp)
cmp    %ecx,%eax
jae    11a8 <put_hexw+0x98>
mov    -0x10(%rbp),%rsi
mov    $0x30,%edi
call   1030 <fputc@plt>
jmp    117f <put_hexw+0x6f>
jmp    11ad <put_hexw+0x9d>
cmpl   $0x0,-0x20(%rbp)
je     11d7 <put_hexw+0xc7>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
mov    %eax,%eax
mov    -0x1a(%rbp,%rax,1),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
jmp    11ad <put_hexw+0x9d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_hexw>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
xor    %ebx,%ebx
mov    %edi,%eax
nop
mov    %edi,%ecx
and    $0xf,%cl
lea    0x30(%rcx),%edx
add    $0x37,%cl
cmp    $0x3a,%dl
movzbl %cl,%ecx
movzbl %dl,%edx
cmovae %ecx,%edx
mov    %dl,0x6(%rsp,%rbx,1)
add    $0x1,%rbx
shr    $0x4,%eax
cmp    $0xf,%edi
mov    %eax,%edi
ja     1120 <put_hexw+0x10>
cmp    $0x3,%ebx
ja     1180 <put_hexw+0x70>
mov    $0x4,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffff,%ebp
mov    $0x30,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
cmp    %ebx,%ebp
ja     1160 <put_hexw+0x50>
test   %ebx,%ebx
je     1193 <put_hexw+0x83>
nopl   0x0(%rax,%rax,1)
movsbl 0x5(%rsp,%rbx,1),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
add    $0xffffffffffffffff,%rbx
jne    1180 <put_hexw+0x70>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @put_hexw(i32 %0, i32* nocapture %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %5, %2
%6 = phi i64 [ %15, %5 ], [ 0, %2 ]
%7 = phi i32 [ %16, %5 ], [ %0, %2 ]
%8 = trunc i32 %7 to i8
%9 = and i8 %8, 15
%10 = or i8 %9, 48
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %6
%12 = icmp ugt i8 %10, 57
%13 = add nuw nsw i8 %9, 55
%14 = select i1 %12, i8 %13, i8 %10
store i8 %14, i8* %11
%15 = add nuw nsw i64 %6, 1
%16 = lshr i32 %7, 4
%17 = icmp ult i32 %7, 16
br i1 %17, label %18, label %5
18: ; preds = %5
%19 = trunc i64 %15 to i32
%20 = icmp ult i32 %19, 4
br i1 %20, label %24, label %23
21: ; preds = %24
%22 = icmp eq i32 %19, 0
br i1 %22, label %36, label %23
23: ; preds = %18, %21
br label %29
24: ; preds = %18, %24
%25 = phi i32 [ %26, %24 ], [ 4, %18 ]
%26 = add nsw i32 %25, -1
%27 = tail call i32 @fputc(i8 signext 48, i32* %1)
%28 = icmp ugt i32 %26, %19
br i1 %28, label %24, label %21
29: ; preds = %23, %29
%30 = phi i64 [ %31, %29 ], [ %15, %23 ]
%31 = add nsw i64 %30, -1
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = tail call i32 @fputc(i8 signext %33, i32* %1)
%35 = icmp eq i64 %31, 0
br i1 %35, label %36, label %29
36: ; preds = %29, %21
ret void
}