#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/ *);
int strlen(char *);
int utf8_to_unicode(int *, char *, int);
int /*<<< orphan*/ willus_mem_alloc_warn(void **, int, char *, int);
int /*<<< orphan*/ willus_mem_free(double **, char *);
int wpdf_docenc_from_utf8(char *, char *, int);
void pdf_utf8_out(FILE *out, char *s) {
  static char *funcname = "pdf_utf8_out";
  int i, len, docenc;
  int *d;
  unsigned char *de;
  willus_mem_alloc_warn((void **)&de, strlen(s) + 2, funcname, 10);
  docenc = wpdf_docenc_from_utf8((char *)de, s, strlen(s) + 1);
  if (docenc) {
    fprintf(out, "(");
    for (i = 0; de[i] != '\0'; i++)
      if (de[i] >= 32 && de[i] <= 127)
        fputc(de[i], out);
      else
        fprintf(out, "\\%03o", de[i]);
    fprintf(out, ")");
  }
  willus_mem_free((double **)&de, funcname);
  if (docenc)
    return;
  len = strlen(s) + 2;
  willus_mem_alloc_warn((void **)&d, sizeof(int) * len, funcname, 10);
  len = utf8_to_unicode(d, s, len - 1);
  fprintf(out, "<FEFF");
  for (i = 0; i < len; i++)
    fprintf(out, "%04X", d[i]);
  fprintf(out, ">");
  willus_mem_free((double **)&d, funcname);
}


x86 assembly (clang, -O0):
<pdf_utf8_out>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
add    $0x2,%esi
mov    0x2ec3(%rip),%rdx
lea    -0x30(%rbp),%rdi
mov    $0xa,%ecx
call   1030 <willus_mem_alloc_warn@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1070 <wpdf_docenc_from_utf8@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1292 <pdf_utf8_out+0x122>
mov    -0x8(%rbp),%rdi
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1280 <pdf_utf8_out+0x110>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     124f <pdf_utf8_out+0xdf>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7f,%eax
jg     124f <pdf_utf8_out+0xdf>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1050 <fputc@plt>
jmp    126d <pdf_utf8_out+0xfd>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1272 <pdf_utf8_out+0x102>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f4 <pdf_utf8_out+0x84>
mov    -0x8(%rbp),%rdi
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2dbb(%rip),%rsi
call   1090 <willus_mem_free@plt>
cmpl   $0x0,-0x1c(%rbp)
je     12b1 <pdf_utf8_out+0x141>
jmp    1367 <pdf_utf8_out+0x1f7>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
mov    0x2d83(%rip),%rdx
mov    $0xa,%ecx
call   1030 <willus_mem_alloc_warn@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
call   1080 <utf8_to_unicode@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xd17(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1345 <pdf_utf8_out+0x1d5>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xced(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    130e <pdf_utf8_out+0x19e>
mov    -0x8(%rbp),%rdi
lea    0xcd2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x28(%rbp),%rdi
mov    0x2cf6(%rip),%rsi
call   1090 <willus_mem_free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pdf_utf8_out>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,%r13
mov    %rsi,%rdi
call   1040 <strlen@plt>
lea    0x2(%rax),%esi
lea    0xe5a(%rip),%rdx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0xa,%ecx
call   1030 <willus_mem_alloc_warn@plt>
mov    0x8(%rsp),%rbp
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbp,%rdi
mov    %r15,%rsi
call   1070 <wpdf_docenc_from_utf8@plt>
test   %eax,%eax
je     123b <pdf_utf8_out+0xbb>
mov    $0x28,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%al
test   %al,%al
je     1231 <pdf_utf8_out+0xb1>
mov    $0x1,%ebp
lea    0xe12(%rip),%r15
jmp    121e <pdf_utf8_out+0x9e>
nopl   (%rax)
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%rsp),%rax
movzbl (%rax,%rbp,1),%eax
add    $0x1,%rbp
test   %al,%al
je     1231 <pdf_utf8_out+0xb1>
movzbl %al,%edx
cmp    $0x20,%al
jl     1200 <pdf_utf8_out+0x80>
mov    %edx,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
jmp    120d <pdf_utf8_out+0x8d>
mov    $0x29,%edi
jmp    12e3 <pdf_utf8_out+0x163>
lea    0xdbe(%rip),%r12
lea    0x8(%rsp),%rdi
mov    %r12,%rsi
call   1090 <willus_mem_free@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0x8(,%rbp,4),%esi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %r12,%rdx
mov    $0xa,%ecx
call   1030 <willus_mem_alloc_warn@plt>
mov    0x10(%rsp),%rdi
add    $0x1,%ebp
mov    %r15,%rsi
mov    %ebp,%edx
call   1080 <utf8_to_unicode@plt>
mov    %eax,%ebp
lea    0xd83(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   10a0 <fwrite@plt>
test   %ebp,%ebp
jle    12de <pdf_utf8_out+0x15e>
mov    %ebp,%ebp
lea    0xd6a(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
mov    (%rax,%rbx,4),%edx
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    12c0 <pdf_utf8_out+0x140>
mov    $0x3e,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
lea    0xd0e(%rip),%rsi
mov    %r14,%rdi
call   1090 <willus_mem_free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@pdf_utf8_out.funcname = internal global i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i32 0, i32 0)
@.str = [13 x i8] c"pdf_utf8_out\00"
@.str.1 = [2 x i8] c"(\00"
@.str.2 = [6 x i8] c"\\%03o\00"
@.str.3 = [2 x i8] c")\00"
@.str.4 = [6 x i8] c"<FEFF\00"
@.str.5 = [5 x i8] c"%04X\00"
@.str.6 = [2 x i8] c">\00"
define void @pdf_utf8_out(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
store i32* %0, i32** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 2
%13 = load i8*, i8** @pdf_utf8_out.funcname
%14 = call i32 @willus_mem_alloc_warn(i8** %9, i32 %12, i8* %13, i32 10)
%15 = load i8*, i8** %9
%16 = load i8*, i8** %4
%17 = load i8*, i8** %4
%18 = call i32 @strlen(i8* %17)
%19 = add nsw i32 %18, 1
%20 = call i32 @wpdf_docenc_from_utf8(i8* %15, i8* %16, i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %74
23: ; preds = %2
%24 = load i32*, i32** %3
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %26
26: ; preds = %68, %23
%27 = load i8*, i8** %9
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %71
34: ; preds = %26
%35 = load i8*, i8** %9
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = icmp sge i32 %40, 32
br i1 %41, label %42, label %58
42: ; preds = %34
%43 = load i8*, i8** %9
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = icmp sle i32 %48, 127
br i1 %49, label %50, label %58
50: ; preds = %42
%51 = load i8*, i8** %9
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = load i32*, i32** %3
%57 = call i32 @fputc(i8 zeroext %55, i32* %56)
br label %67
58: ; preds = %42, %34
%59 = load i32*, i32** %3
%60 = load i8*, i8** %9
%61 = load i32, i32* %5
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = call i32 (i32*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %58, %50
br label %68
68: ; preds = %67
%69 = load i32, i32* %5
%70 = add nsw i32 %69, 1
store i32 %70, i32* %5
br label %26
71: ; preds = %26
%72 = load i32*, i32** %3
%73 = call i32 (i32*, i8*, ...) @fprintf(i32* %72, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %74
74: ; preds = %71, %2
%75 = bitcast i8** %9 to double**
%76 = load i8*, i8** @pdf_utf8_out.funcname
%77 = call i32 @willus_mem_free(double** %75, i8* %76)
%78 = load i32, i32* %7
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %74
br label %120
81: ; preds = %74
%82 = load i8*, i8** %4
%83 = call i32 @strlen(i8* %82)
%84 = add nsw i32 %83, 2
store i32 %84, i32* %6
%85 = bitcast i32** %8 to i8**
%86 = load i32, i32* %6
%87 = sext i32 %86 to i64
%88 = mul i64 4, %87
%89 = trunc i64 %88 to i32
%90 = load i8*, i8** @pdf_utf8_out.funcname
%91 = call i32 @willus_mem_alloc_warn(i8** %85, i32 %89, i8* %90, i32 10)
%92 = load i32*, i32** %8
%93 = load i8*, i8** %4
%94 = load i32, i32* %6
%95 = sub nsw i32 %94, 1
%96 = call i32 @utf8_to_unicode(i32* %92, i8* %93, i32 %95)
store i32 %96, i32* %6
%97 = load i32*, i32** %3
%98 = call i32 (i32*, i8*, ...) @fprintf(i32* %97, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %5
br label %99
99: ; preds = %111, %81
%100 = load i32, i32* %5
%101 = load i32, i32* %6
%102 = icmp slt i32 %100, %101
br i1 %102, label %103, label %114
103: ; preds = %99
%104 = load i32*, i32** %3
%105 = load i32*, i32** %8
%106 = load i32, i32* %5
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i32, i32* %105, i64 %107
%109 = load i32, i32* %108
%110 = call i32 (i32*, i8*, ...) @fprintf(i32* %104, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %109)
br label %111
111: ; preds = %103
%112 = load i32, i32* %5
%113 = add nsw i32 %112, 1
store i32 %113, i32* %5
br label %99
114: ; preds = %99
%115 = load i32*, i32** %3
%116 = call i32 (i32*, i8*, ...) @fprintf(i32* %115, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%117 = bitcast i32** %8 to double**
%118 = load i8*, i8** @pdf_utf8_out.funcname
%119 = call i32 @willus_mem_free(double** %117, i8* %118)
br label %120
120: ; preds = %114, %80
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"pdf_utf8_out\00"
@.str.2 = [6 x i8] c"\\%03o\00"
@.str.4 = [6 x i8] c"<FEFF\00"
@.str.5 = [5 x i8] c"%04X\00"
define void @pdf_utf8_out(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = bitcast i32** %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = tail call i32 @strlen(i8* %1)
%8 = add nsw i32 %7, 2
%9 = call i32 @willus_mem_alloc_warn(i8** %4, i32 %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 10)
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %1)
%12 = add nsw i32 %11, 1
%13 = call i32 @wpdf_docenc_from_utf8(i8* %10, i8* %1, i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %38, label %15
15: ; preds = %2
%16 = call i32 bitcast (i32 (i8, i32*)* @fputc to i32 (i32, i32*)*)(i32 40, i32* %0)
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %35, label %20
20: ; preds = %15, %29
%21 = phi i64 [ %30, %29 ], [ 0, %15 ]
%22 = phi i8 [ %33, %29 ], [ %18, %15 ]
%23 = icmp sgt i8 %22, 31
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @fputc(i8 zeroext %22, i32* %0)
br label %29
26: ; preds = %20
%27 = zext i8 %22 to i32
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %24, %26
%30 = add nuw i64 %21, 1
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 %30
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %35, label %20
35: ; preds = %29, %15
%36 = call i32 bitcast (i32 (i8, i32*)* @fputc to i32 (i32, i32*)*)(i32 41, i32* %0)
%37 = bitcast i8** %4 to double**
br label %64
38: ; preds = %2
%39 = bitcast i8** %4 to double**
%40 = call i32 @willus_mem_free(double** %39, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%41 = call i32 @strlen(i8* %1)
%42 = bitcast i32** %3 to i8**
%43 = shl i32 %41, 2
%44 = add i32 %43, 8
%45 = call i32 @willus_mem_alloc_warn(i8** %42, i32 %44, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 10)
%46 = load i32*, i32** %3
%47 = add nsw i32 %41, 1
%48 = call i32 @utf8_to_unicode(i32* %46, i8* %1, i32 %47)
%49 = call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i64 5, i64 1, i32* %0)
%50 = icmp sgt i32 %48, 0
br i1 %50, label %51, label %61
51: ; preds = %38
%52 = zext i32 %48 to i64
br label %53
53: ; preds = %51, %53
%54 = phi i64 [ 0, %51 ], [ %59, %53 ]
%55 = load i32*, i32** %3
%56 = getelementptr inbounds i32, i32* %55, i64 %54
%57 = load i32, i32* %56
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %57)
%59 = add nuw nsw i64 %54, 1
%60 = icmp eq i64 %59, %52
br i1 %60, label %61, label %53
61: ; preds = %53, %38
%62 = call i32 bitcast (i32 (i8, i32*)* @fputc to i32 (i32, i32*)*)(i32 62, i32* %0)
%63 = bitcast i32** %3 to double**
br label %64
64: ; preds = %35, %61
%65 = phi double** [ %37, %35 ], [ %63, %61 ]
%66 = call i32 @willus_mem_free(double** %65, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
ret void
}