#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 */
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct printf_info {
  int dummy;
};
struct TYPE_4__ {
  int /*<<< orphan*/ member_0;
};
struct TYPE_5__ {
  TYPE_1__ member_1;
  int /*<<< orphan*/ member_0;
};
typedef TYPE_2__ mbstate_t;
typedef int char32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int MB_CUR_MAX;
int c32rtomb(char *, int const, TYPE_2__ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int const);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int print_char32(FILE *stream, const struct printf_info *info,
                 const void *const *args) {
  const char32_t *str = *((const char32_t **)(args[0]));
  int r, l, n = 0;
  char mb[MB_CUR_MAX];
  while (*str) {
    mbstate_t ps = {0, {0}};
    n += (l = c32rtomb(mb, *str, &ps));
    if (l == (size_t)-1) {
      if ((*str) >> 16)
        fprintf(stream, "\\u%4.4X", (*str) >> 16);
      fprintf(stream, "\\u%4.4X", (*str) & 0xFFFF);
    } else if ((r = fwrite(mb, l, 1, stream)) < 0)
      return r;
    ++str;
  }
  return n;
}


x86 assembly (clang, -O0):
<print_char32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
je     1271 <print_char32+0x131>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   1040 <c32rtomb@plt>
mov    %eax,-0x30(%rbp)
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
movslq -0x30(%rbp),%rax
cmp    $0xffffffffffffffff,%rax
jne    1228 <print_char32+0xe8>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
sar    $0x10,%eax
cmp    $0x0,%eax
je     1207 <print_char32+0xc7>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
sar    $0x10,%edx
lea    0xdfe(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
and    $0xffff,%edx
lea    0xde2(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1260 <print_char32+0x120>
mov    -0x60(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    125b <print_char32+0x11b>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    127e <print_char32+0x13e>
jmp    1260 <print_char32+0x120>
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
jmp    1195 <print_char32+0x55>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_char32>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdx),%rax
mov    (%rax),%r12
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
cmpl   $0x0,(%r12)
je     11f7 <print_char32+0xc7>
mov    %rdi,%r14
xor    %ebx,%ebx
jmp    1197 <print_char32+0x67>
mov    %r15,%rdi
mov    %r13d,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fwrite@plt>
test   %eax,%eax
js     11fb <print_char32+0xcb>
add    %r13d,%ebx
cmpl   $0x0,0x4(%r12)
lea    0x4(%r12),%r12
je     11fd <print_char32+0xcd>
movq   $0x0,-0x30(%rbp)
mov    (%r12),%esi
mov    %r15,%rdi
lea    -0x30(%rbp),%rdx
call   1030 <c32rtomb@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
jne    1170 <print_char32+0x40>
mov    (%r12),%edx
cmp    $0x10000,%edx
jae    11cc <print_char32+0x9c>
lea    0xe36(%rip),%rsi
jmp    11ea <print_char32+0xba>
sar    $0x10,%edx
mov    %r14,%rdi
lea    0xe27(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xe1b(%rip),%rsi
movzwl (%r12),%edx
movzwl %dx,%edx
mov    %r14,%rdi
call   1040 <fprintf@plt>
jmp    1187 <print_char32+0x57>
xor    %ebx,%ebx
jmp    11fd <print_char32+0xcd>
mov    %eax,%ebx
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.printf_info = type { i32 }
%struct.TYPE_5__ = type { %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { i32 }
@MB_CUR_MAX = global i32 0
@.str = [8 x i8] c"\\u%4.4X\00"
define i32 @print_char32(i32* nocapture %0, %struct.printf_info* nocapture readnone %1, i8** nocapture %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to %struct.TYPE_5__*
%6 = bitcast i8** %2 to i32***
%7 = load i32**, i32*** %6
%8 = load i32*, i32** %7
%9 = load i32, i32* @MB_CUR_MAX
%10 = zext i32 %9 to i64
%11 = alloca i8, i64 %10
%12 = load i32, i32* %8
%13 = icmp eq i32 %12, 0
br i1 %13, label %42, label %14
14: ; preds = %3
%15 = bitcast i64* %4 to i8*
br label %16
16: ; preds = %14, %38
%17 = phi i32* [ %8, %14 ], [ %39, %38 ]
%18 = phi i32 [ 0, %14 ], [ %21, %38 ]
store i64 0, i64* %4
%19 = load i32, i32* %17
%20 = call i32 @c32rtomb(i8* %11, i32 %19, %struct.TYPE_5__* %5)
%21 = add nsw i32 %20, %18
%22 = icmp eq i32 %20, -1
br i1 %22, label %23, label %34
23: ; preds = %16
%24 = load i32, i32* %17
%25 = icmp ult i32 %24, 65536
br i1 %25, label %30, label %26
26: ; preds = %23
%27 = ashr i32 %24, 16
%28 = call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %17
br label %30
30: ; preds = %26, %23
%31 = phi i32 [ %29, %26 ], [ %24, %23 ]
%32 = and i32 %31, 65535
%33 = call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %32)
br label %38
34: ; preds = %16
%35 = call i32 @fwrite(i8* %11, i32 %20, i32 1, i32* %0)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %34
br label %42
38: ; preds = %30, %34
%39 = getelementptr inbounds i32, i32* %17, i64 1
%40 = load i32, i32* %39
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %16
42: ; preds = %38, %3, %37
%43 = phi i32 [ %35, %37 ], [ 0, %3 ], [ %21, %38 ]
ret i32 %43
}