#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 */
struct generator {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ write_hexdigit(struct generator *, int);
int /*<<< orphan*/ write_string(struct generator *, char *);
void write_hex(struct generator *g, int ch) {
  write_string(g, "\\u");
  {
    int i;
    for (i = 12; i >= 0; i -= 4)
      write_hexdigit(g, ch >> i & 0xf);
  }
}


x86 assembly (clang, -O0):
<write_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec6(%rip),%rsi
call   1030 <write_string@plt>
movl   $0xc,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1172 <write_hex+0x52>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%ecx
sar    %cl,%esi
and    $0xf,%esi
call   1040 <write_hexdigit@plt>
mov    -0x10(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x10(%rbp)
jmp    1146 <write_hex+0x26>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_hex>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xed0(%rip),%rsi
call   1030 <write_string@plt>
mov    %ebx,%esi
shr    $0xc,%esi
and    $0xf,%esi
mov    %r14,%rdi
call   1040 <write_hexdigit@plt>
mov    %ebx,%esi
shr    $0x8,%esi
and    $0xf,%esi
mov    %r14,%rdi
call   1040 <write_hexdigit@plt>
mov    %ebx,%esi
shr    $0x4,%esi
and    $0xf,%esi
mov    %r14,%rdi
call   1040 <write_hexdigit@plt>
and    $0xf,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <write_hexdigit@plt>

LLVM IR (-O0):
%struct.generator = type { i32 }
@.str = [3 x i8] c"\\u\00"
define void @write_hex(%struct.generator* %0, i32 %1) {
%3 = alloca %struct.generator*
%4 = alloca i32
%5 = alloca i32
store %struct.generator* %0, %struct.generator** %3
store i32 %1, i32* %4
%6 = load %struct.generator*, %struct.generator** %3
%7 = call i32 @write_string(%struct.generator* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 12, i32* %5
br label %8
8: ; preds = %18, %2
%9 = load i32, i32* %5
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = load %struct.generator*, %struct.generator** %3
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = ashr i32 %13, %14
%16 = and i32 %15, 15
%17 = call i32 @write_hexdigit(%struct.generator* %12, i32 %16)
br label %18
18: ; preds = %11
%19 = load i32, i32* %5
%20 = sub nsw i32 %19, 4
store i32 %20, i32* %5
br label %8
21: ; preds = %8
ret void
}

LLVM IR (-O2):
%struct.generator = type { i32 }
@.str = [3 x i8] c"\\u\00"
define void @write_hex(%struct.generator* %0, i32 %1) {
%3 = tail call i32 @write_string(%struct.generator* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = lshr i32 %1, 12
%5 = and i32 %4, 15
%6 = tail call i32 @write_hexdigit(%struct.generator* %0, i32 %5)
%7 = lshr i32 %1, 8
%8 = and i32 %7, 15
%9 = tail call i32 @write_hexdigit(%struct.generator* %0, i32 %8)
%10 = lshr i32 %1, 4
%11 = and i32 %10, 15
%12 = tail call i32 @write_hexdigit(%struct.generator* %0, i32 %11)
%13 = and i32 %1, 15
%14 = tail call i32 @write_hexdigit(%struct.generator* %0, i32 %13)
ret void
}