#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_hexb(unsigned char value, FILE *fout) {
  char stack[10];
  unsigned int i, j;
  i = 0;
  j = 2;
  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_hexb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x2,-0x24(%rbp)
movzbl -0x1(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%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    1168 <put_hexb+0x58>
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)
movzbl -0x1(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %al,-0x1(%rbp)
cmp    $0x0,%al
jne    1130 <put_hexb+0x20>
jmp    118d <put_hexb+0x7d>
mov    -0x20(%rbp),%eax
mov    -0x24(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x24(%rbp)
cmp    %ecx,%eax
jae    11b6 <put_hexb+0xa6>
mov    -0x10(%rbp),%rsi
mov    $0x30,%edi
call   1030 <fputc@plt>
jmp    118d <put_hexb+0x7d>
jmp    11bb <put_hexb+0xab>
cmpl   $0x0,-0x20(%rbp)
je     11e5 <put_hexb+0xd5>
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    11bb <put_hexb+0xab>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_hexb>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
xor    %ebx,%ebx
mov    %edi,%eax
xchg   %ax,%ax
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,0xe(%rsp,%rbx,1)
add    $0x1,%rbx
shr    $0x4,%al
cmp    $0xf,%dil
mov    %eax,%edi
ja     1120 <put_hexb+0x10>
cmp    $0x1,%ebx
ja     1160 <put_hexb+0x50>
mov    $0x30,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
test   %ebx,%ebx
je     1173 <put_hexb+0x63>
movsbl 0xd(%rsp,%rbx,1),%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
add    $0xffffffffffffffff,%rbx
jne    1160 <put_hexb+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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