#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 EOF;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ json_escape(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
void latin1_json(FILE *in, FILE *out) {
  int c;
  while ((c = getc(in)) != EOF) {
    int e = -1;
    switch (c) {
    case 0x22:
    case 0x5C:
    case 0x2F:
      e = c;
      break;
    case 0x08:
      e = 0x62;
      break;
    case 0x0C:
      e = 0x66;
      break;
    case 0x0A:
      e = 0x6E;
      break;
    case 0x0D:
      e = 0x72;
      break;
    case 0x09:
      e = 0x74;
      break;
    }
    if (e != -1) {
      json_escape(e, out);
    } else if (c <= 0x1F) {
      fprintf(out, "\\u00%.2x", c);
    } else if (c <= 0x7F) {
      putc(c, out);
    } else {
      putc(0xC0 | (c >> 6), out);
      putc(0x80 | (c & 0x3F), out);
    }
  }
}


x86 assembly (clang, -O0):
<latin1_json>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e85(%rip),%rcx
cmp    (%rcx),%eax
je     12d0 <latin1_json+0x190>
movl   $0xffffffff,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x8,%eax
je     1208 <latin1_json+0xc8>
jmp    1186 <latin1_json+0x46>
mov    -0x1c(%rbp),%eax
sub    $0x9,%eax
je     1238 <latin1_json+0xf8>
jmp    1197 <latin1_json+0x57>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     1220 <latin1_json+0xe0>
jmp    11a8 <latin1_json+0x68>
mov    -0x1c(%rbp),%eax
sub    $0xc,%eax
je     1214 <latin1_json+0xd4>
jmp    11b9 <latin1_json+0x79>
mov    -0x1c(%rbp),%eax
sub    $0xd,%eax
je     122c <latin1_json+0xec>
jmp    11ca <latin1_json+0x8a>
mov    -0x1c(%rbp),%eax
sub    $0x22,%eax
je     11fd <latin1_json+0xbd>
jmp    11db <latin1_json+0x9b>
mov    -0x1c(%rbp),%eax
sub    $0x2f,%eax
je     11fd <latin1_json+0xbd>
jmp    11ec <latin1_json+0xac>
mov    -0x1c(%rbp),%eax
sub    $0x5c,%eax
jne    123f <latin1_json+0xff>
jmp    11fd <latin1_json+0xbd>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    123f <latin1_json+0xff>
movl   $0x62,-0x18(%rbp)
jmp    123f <latin1_json+0xff>
movl   $0x66,-0x18(%rbp)
jmp    123f <latin1_json+0xff>
movl   $0x6e,-0x18(%rbp)
jmp    123f <latin1_json+0xff>
movl   $0x72,-0x18(%rbp)
jmp    123f <latin1_json+0xff>
movl   $0x74,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
je     125a <latin1_json+0x11a>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <json_escape@plt>
jmp    12cb <latin1_json+0x18b>
cmpl   $0x1f,-0x14(%rbp)
jg     127c <latin1_json+0x13c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xd8e(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12c6 <latin1_json+0x186>
cmpl   $0x7f,-0x14(%rbp)
jg     1297 <latin1_json+0x157>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <putc@plt>
jmp    12c1 <latin1_json+0x181>
mov    -0x14(%rbp),%edi
sar    $0x6,%edi
or     $0xc0,%edi
mov    -0x10(%rbp),%rsi
call   1040 <putc@plt>
mov    -0x14(%rbp),%edi
and    $0x3f,%edi
or     $0x80,%edi
mov    -0x10(%rbp),%rsi
call   1040 <putc@plt>
jmp    12c6 <latin1_json+0x186>
jmp    12cb <latin1_json+0x18b>
jmp    1150 <latin1_json+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<latin1_json>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1060 <getc@plt>
mov    0x2e8b(%rip),%r13
cmp    0x0(%r13),%eax
jne    1172 <latin1_json+0x32>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
lea    0xf25(%rip),%r15
lea    0xe7e(%rip),%rbp
jmp    11aa <latin1_json+0x6a>
mov    $0x74,%ebx
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <json_escape@plt>
mov    %r12,%rdi
call   1060 <getc@plt>
mov    %eax,%ebx
cmp    0x0(%r13),%eax
je     1163 <latin1_json+0x23>
lea    -0x8(%rbx),%eax
cmp    $0x27,%eax
ja     11c3 <latin1_json+0x83>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
mov    $0x62,%ebx
jmp    1190 <latin1_json+0x50>
cmp    $0x5c,%ebx
je     1190 <latin1_json+0x50>
cmp    $0x1f,%ebx
jg     11f1 <latin1_json+0xb1>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <fprintf@plt>
jmp    119a <latin1_json+0x5a>
mov    $0x6e,%ebx
jmp    1190 <latin1_json+0x50>
mov    $0x66,%ebx
jmp    1190 <latin1_json+0x50>
mov    $0x72,%ebx
jmp    1190 <latin1_json+0x50>
cmp    $0x7f,%ebx
jbe    1212 <latin1_json+0xd2>
mov    %ebx,%edi
shr    $0x6,%edi
or     $0xc0,%edi
mov    %r14,%rsi
call   1040 <putc@plt>
and    $0x3f,%ebx
or     $0x80,%ebx
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <putc@plt>
jmp    119a <latin1_json+0x5a>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [9 x i8] c"\\u00%.2x\00"
define void @latin1_json(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
br label %7
7: ; preds = %55, %2
%8 = load i32*, i32** %3
%9 = call i32 @getc(i32* %8)
store i32 %9, i32* %5
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %56
12: ; preds = %7
store i32 -1, i32* %6
%13 = load i32, i32* %5
switch i32 %13, label %21 [
i32 34, label %14
i32 92, label %14
i32 47, label %14
i32 8, label %16
i32 12, label %17
i32 10, label %18
i32 13, label %19
i32 9, label %20
]
14: ; preds = %12, %12, %12
%15 = load i32, i32* %5
store i32 %15, i32* %6
br label %21
16: ; preds = %12
store i32 98, i32* %6
br label %21
17: ; preds = %12
store i32 102, i32* %6
br label %21
18: ; preds = %12
store i32 110, i32* %6
br label %21
19: ; preds = %12
store i32 114, i32* %6
br label %21
20: ; preds = %12
store i32 116, i32* %6
br label %21
21: ; preds = %12, %20, %19, %18, %17, %16, %14
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* %6
%26 = load i32*, i32** %4
%27 = call i32 @json_escape(i32 %25, i32* %26)
br label %55
28: ; preds = %21
%29 = load i32, i32* %5
%30 = icmp sle i32 %29, 31
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i32*, i32** %4
%33 = load i32, i32* %5
%34 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %54
35: ; preds = %28
%36 = load i32, i32* %5
%37 = icmp sle i32 %36, 127
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load i32, i32* %5
%40 = load i32*, i32** %4
%41 = call i32 @putc(i32 %39, i32* %40)
br label %53
42: ; preds = %35
%43 = load i32, i32* %5
%44 = ashr i32 %43, 6
%45 = or i32 192, %44
%46 = load i32*, i32** %4
%47 = call i32 @putc(i32 %45, i32* %46)
%48 = load i32, i32* %5
%49 = and i32 %48, 63
%50 = or i32 128, %49
%51 = load i32*, i32** %4
%52 = call i32 @putc(i32 %50, i32* %51)
br label %53
53: ; preds = %42, %38
br label %54
54: ; preds = %53, %31
br label %55
55: ; preds = %54, %24
br label %7
56: ; preds = %7
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [9 x i8] c"\\u00%.2x\00"
define void @latin1_json(i32* nocapture %0, i32* %1) {
%3 = tail call i32 @getc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %35, label %6
6: ; preds = %2, %31
%7 = phi i32 [ %32, %31 ], [ %3, %2 ]
switch i32 %7, label %16 [
i32 34, label %13
i32 92, label %13
i32 47, label %13
i32 8, label %8
i32 12, label %9
i32 10, label %10
i32 13, label %11
i32 9, label %12
]
8: ; preds = %6
br label %13
9: ; preds = %6
br label %13
10: ; preds = %6
br label %13
11: ; preds = %6
br label %13
12: ; preds = %6
br label %13
13: ; preds = %6, %6, %6, %12, %11, %10, %9, %8
%14 = phi i32 [ 98, %8 ], [ 102, %9 ], [ 110, %10 ], [ 114, %11 ], [ 116, %12 ], [ %7, %6 ], [ %7, %6 ], [ %7, %6 ]
%15 = tail call i32 @json_escape(i32 %14, i32* %1)
br label %31
16: ; preds = %6
%17 = icmp slt i32 %7, 32
br i1 %17, label %18, label %20
18: ; preds = %16
%19 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %31
20: ; preds = %16
%21 = icmp ult i32 %7, 128
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = tail call i32 @putc(i32 %7, i32* %1)
br label %31
24: ; preds = %20
%25 = lshr i32 %7, 6
%26 = or i32 %25, 192
%27 = tail call i32 @putc(i32 %26, i32* %1)
%28 = and i32 %7, 63
%29 = or i32 %28, 128
%30 = tail call i32 @putc(i32 %29, i32* %1)
br label %31
31: ; preds = %18, %24, %22, %13
%32 = tail call i32 @getc(i32* %0)
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %6
35: ; preds = %31, %2
ret void
}