#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ convertLine(char *);
int /*<<< orphan*/ convertSJISLine(char *);
int createTables();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int main(int argc, char *argv[]) {
  FILE *file;
  char buffer[BUFSIZ];
  int error;
  if ((file = fopen("Unihan.txt", "r")) == NULL) {
    perror("Unihan.txt");
    return 1;
  }
  while (fgets(buffer, sizeof(buffer), file)) {
    if (buffer[0] == 'U' && buffer[1] == '+') {
      convertLine(buffer + 2);
    }
  }
  fclose(file);
  if ((file = fopen("CP932.TXT", "r")) == NULL) {
    perror("CP932.TXT");
    return 1;
  }
  while (fgets(buffer, sizeof(buffer), file)) {
    if (buffer[0] == '0' && buffer[1] == 'x') {
      convertSJISLine(buffer + 2);
    }
  }
  fclose(file);
  error = createTables();
  return error;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xe43(%rip),%rdi
lea    0xe47(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f6 <main+0x86>
lea    0xe22(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    1309 <main+0x199>
jmp    11fb <main+0x8b>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     124b <main+0xdb>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x55,%eax
jne    1246 <main+0xd6>
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2b,%eax
jne    1246 <main+0xd6>
mov    -0x38(%rbp),%rdi
add    $0x2,%rdi
call   1080 <convertLine@plt>
jmp    11fb <main+0x8b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdb2(%rip),%rdi
lea    0xda9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1294 <main+0x124>
lea    0xd91(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    1309 <main+0x199>
jmp    1299 <main+0x129>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     12e9 <main+0x179>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    12e4 <main+0x174>
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
jne    12e4 <main+0x174>
mov    -0x38(%rbp),%rdi
add    $0x2,%rdi
call   1070 <convertSJISLine@plt>
jmp    1299 <main+0x129>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x0,%al
call   1090 <createTables@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e5e(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe63(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1284 <main+0x114>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11f8 <main+0x88>
lea    0x2(%rbx),%r12
jmp    11e3 <main+0x73>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11f8 <main+0x88>
cmpb   $0x55,(%rbx)
jne    11d0 <main+0x60>
cmpb   $0x2b,0x1(%rbx)
jne    11d0 <main+0x60>
mov    %r12,%rdi
call   1080 <convertLine@plt>
jmp    11d0 <main+0x60>
mov    %r15,%rdi
call   1030 <fclose@plt>
lea    0xe06(%rip),%rdi
lea    0xdfd(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     128d <main+0x11d>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1268 <main+0xf8>
lea    0x2(%rbx),%r12
jmp    1253 <main+0xe3>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1268 <main+0xf8>
cmpb   $0x30,(%rbx)
jne    1240 <main+0xd0>
cmpb   $0x78,0x1(%rbx)
jne    1240 <main+0xd0>
mov    %r12,%rdi
call   1070 <convertSJISLine@plt>
jmp    1240 <main+0xd0>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
call   1090 <createTables@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd75(%rip),%rdi
jmp    1294 <main+0x124>
lea    0xd79(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
jmp    1277 <main+0x107>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [11 x i8] c"Unihan.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"CP932.TXT\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i8, i64 %12
store i64 %12, i64* %8
%15 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %6
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %10
br label %71
19: ; preds = %2
br label %20
20: ; preds = %38, %19
%21 = trunc i64 %12 to i32
%22 = load i32*, i32** %6
%23 = call i64 @fgets(i8* %14, i32 %21, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %39
25: ; preds = %20
%26 = getelementptr inbounds i8, i8* %14, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 85
br i1 %29, label %30, label %38
30: ; preds = %25
%31 = getelementptr inbounds i8, i8* %14, i64 1
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 43
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = getelementptr inbounds i8, i8* %14, i64 2
%37 = call i32 @convertLine(i8* %36)
br label %38
38: ; preds = %35, %30, %25
br label %20
39: ; preds = %20
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
%42 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %42, i32** %6
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %46
44: ; preds = %39
%45 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %10
br label %71
46: ; preds = %39
br label %47
47: ; preds = %65, %46
%48 = trunc i64 %12 to i32
%49 = load i32*, i32** %6
%50 = call i64 @fgets(i8* %14, i32 %48, i32* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %66
52: ; preds = %47
%53 = getelementptr inbounds i8, i8* %14, i64 0
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 48
br i1 %56, label %57, label %65
57: ; preds = %52
%58 = getelementptr inbounds i8, i8* %14, i64 1
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 120
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = getelementptr inbounds i8, i8* %14, i64 2
%64 = call i32 @convertSJISLine(i8* %63)
br label %65
65: ; preds = %62, %57, %52
br label %47
66: ; preds = %47
%67 = load i32*, i32** %6
%68 = call i32 @fclose(i32* %67)
%69 = call i32 (...) @createTables()
store i32 %69, i32* %9
%70 = load i32, i32* %9
store i32 %70, i32* %3
store i32 1, i32* %10
br label %71
71: ; preds = %66, %44, %17
%72 = load i8*, i8** %7
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [11 x i8] c"Unihan.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"CP932.TXT\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = call i64 @fgets(i8* %5, i32 %3, i32* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %27, label %11
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %5, i64 1
%13 = getelementptr inbounds i8, i8* %5, i64 2
br label %16
14: ; preds = %2
%15 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %53
16: ; preds = %11, %24
%17 = load i8, i8* %5
%18 = icmp eq i8 %17, 85
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i8, i8* %12
%21 = icmp eq i8 %20, 43
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @convertLine(i8* %13)
br label %24
24: ; preds = %22, %19, %16
%25 = call i64 @fgets(i8* %5, i32 %3, i32* %6)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %16
27: ; preds = %24, %8
%28 = call i32 @fclose(i32* %6)
%29 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %37, label %31
31: ; preds = %27
%32 = call i64 @fgets(i8* %5, i32 %3, i32* %29)
%33 = icmp eq i64 %32, 0
br i1 %33, label %50, label %34
34: ; preds = %31
%35 = getelementptr inbounds i8, i8* %5, i64 1
%36 = getelementptr inbounds i8, i8* %5, i64 2
br label %39
37: ; preds = %27
%38 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %53
39: ; preds = %34, %47
%40 = load i8, i8* %5
%41 = icmp eq i8 %40, 48
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load i8, i8* %35
%44 = icmp eq i8 %43, 120
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 @convertSJISLine(i8* %36)
br label %47
47: ; preds = %45, %42, %39
%48 = call i64 @fgets(i8* %5, i32 %3, i32* %29)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %39
50: ; preds = %47, %31
%51 = call i32 @fclose(i32* %29)
%52 = call i32 (...) @createTables()
br label %53
53: ; preds = %50, %37, %14
%54 = phi i32 [ 1, %14 ], [ 1, %37 ], [ %52, %50 ]
ret i32 %54
}