#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ handle_cp(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ handle_jis(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
void *strrchr(char const *, char);
int main(int argc, char **argv) {
  int i;
  const char *filename, *p;
  char *q;
  char name[256];
  FILE *f;
  printf("#include \"qe.h\"\n\n");
  for (i = 1; i < argc; i++) {
    filename = argv[i];
    p = strrchr(filename, '/');
    if (!p)
      p = filename;
    else
      p++;
    strcpy(name, p);
    q = strrchr(name, '.');
    if (q)
      *q = '\0';
    f = fopen(filename, "r");
    if (!f) {
      perror(filename);
      exit(1);
    }
    if (!strcmp(name, "JIS0208"))
      handle_jis(f, 1);
    else if (!strcmp(name, "JIS0212"))
      handle_jis(f, 0);
    else
      handle_cp(f, name);
    fclose(f);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe40(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1320 <main+0x180>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1212 <main+0x72>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    121e <main+0x7e>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x130(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1255 <main+0xb5>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x138(%rbp)
cmpq   $0x0,-0x138(%rbp)
jne    128d <main+0xed>
mov    -0x20(%rbp),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x130(%rbp),%rdi
lea    0xd79(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    12bf <main+0x11f>
mov    -0x138(%rbp),%rdi
mov    $0x1,%esi
call   1080 <handle_jis@plt>
jmp    1306 <main+0x166>
lea    -0x130(%rbp),%rdi
lea    0xd4f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    12ee <main+0x14e>
mov    -0x138(%rbp),%rdi
xor    %esi,%esi
call   1080 <handle_jis@plt>
jmp    1301 <main+0x161>
mov    -0x138(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   10b0 <handle_cp@plt>
jmp    1306 <main+0x166>
mov    -0x138(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cc <main+0x2c>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x2,%ebx
jl     128f <main+0xff>
mov    %ebx,%ebp
mov    $0x1,%r15d
mov    %rsp,%r12
jmp    11ed <main+0x5d>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rsi
call   10a0 <handle_cp@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0x1,%r15
cmp    %r15,%rbp
je     128f <main+0xff>
mov    (%r14,%r15,8),%r13
mov    %r13,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
lea    0x1(%rax),%rsi
test   %rax,%rax
cmove  %r13,%rsi
mov    %r12,%rdi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     1226 <main+0x96>
movb   $0x0,(%rax)
mov    %r13,%rdi
lea    0xdd0(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12a3 <main+0x113>
mov    %rax,%rbx
mov    (%rsp),%rax
movabs $0x3231323053494a,%rcx
cmp    %rcx,%rax
je     1280 <main+0xf0>
movabs $0x3830323053494a,%rcx
mov    %rbx,%rdi
cmp    %rcx,%rax
jne    11d0 <main+0x40>
mov    $0x1,%esi
call   1070 <handle_jis@plt>
jmp    11d8 <main+0x48>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <handle_jis@plt>
jmp    11d8 <main+0x48>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"#include \22qe.h\22\0A\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"JIS0208\00"
@.str.3 = [8 x i8] c"JIS0212\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 i8*
%9 = alloca i8*
%10 = alloca [256 x i8]
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %13
13: ; preds = %73, %2
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %76
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = call i8* @strrchr(i8* %23, i8 signext 47)
store i8* %24, i8** %8
%25 = load i8*, i8** %8
%26 = icmp ne i8* %25, null
br i1 %26, label %29, label %27
27: ; preds = %17
%28 = load i8*, i8** %7
store i8* %28, i8** %8
br label %32
29: ; preds = %17
%30 = load i8*, i8** %8
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %8
br label %32
32: ; preds = %29, %27
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%34 = load i8*, i8** %8
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%37 = call i8* @strrchr(i8* %36, i8 signext 46)
store i8* %37, i8** %9
%38 = load i8*, i8** %9
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %42
40: ; preds = %32
%41 = load i8*, i8** %9
store i8 0, i8* %41
br label %42
42: ; preds = %40, %32
%43 = load i8*, i8** %7
%44 = call i32* @fopen(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %44, i32** %11
%45 = load i32*, i32** %11
%46 = icmp ne i32* %45, null
br i1 %46, label %51, label %47
47: ; preds = %42
%48 = load i8*, i8** %7
%49 = call i32 @perror(i8* %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %42
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%53 = call i32 @strcmp(i8* %52, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%54 = icmp ne i32 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %51
%56 = load i32*, i32** %11
%57 = call i32 @handle_jis(i32* %56, i32 1)
br label %70
58: ; preds = %51
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%60 = call i32 @strcmp(i8* %59, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%61 = icmp ne i32 %60, 0
br i1 %61, label %65, label %62
62: ; preds = %58
%63 = load i32*, i32** %11
%64 = call i32 @handle_jis(i32* %63, i32 0)
br label %69
65: ; preds = %58
%66 = load i32*, i32** %11
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%68 = call i32 @handle_cp(i32* %66, i8* %67)
br label %69
69: ; preds = %65, %62
br label %70
70: ; preds = %69, %55
%71 = load i32*, i32** %11
%72 = call i32 @fclose(i32* %71)
br label %73
73: ; preds = %70
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
store i32 %75, i32* %6
br label %13
76: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@str = [17 x i8] c"#include \22qe.h\22\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %40
7: ; preds = %2
%8 = bitcast [256 x i8]* %3 to i64*
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %7, %36
%11 = phi i64 [ 1, %7 ], [ %38, %36 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = call i8* @strrchr(i8* dereferenceable(1) %13, i8 signext 47)
%15 = icmp eq i8* %14, null
%16 = getelementptr inbounds i8, i8* %14, i64 1
%17 = select i1 %15, i8* %13, i8* %16
%18 = call i32 @strcpy(i8* %4, i8* %17)
%19 = call i8* @strrchr(i8* %4, i8 signext 46)
%20 = icmp eq i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %10
store i8 0, i8* %19
br label %22
22: ; preds = %21, %10
%23 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = call i32 @perror(i8* %13)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %22
%29 = load i64, i64* %8
switch i64 %29, label %34 [
i64 15815590813059402, label %30
i64 14127840464423242, label %32
]
30: ; preds = %28
%31 = call i32 @handle_jis(i32* %23, i32 1)
br label %36
32: ; preds = %28
%33 = call i32 @handle_jis(i32* %23, i32 0)
br label %36
34: ; preds = %28
%35 = call i32 @handle_cp(i32* %23, i8* %4)
br label %36
36: ; preds = %32, %34, %30
%37 = call i32 @fclose(i32* %23)
%38 = add nuw nsw i64 %11, 1
%39 = icmp eq i64 %38, %9
br i1 %39, label %40, label %10
40: ; preds = %36, %2
ret i32 0
}