#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 */

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcmp(char *, char *);
char *toStringEUC(char *);
char *toStringJIS(char *);
char *toStringSJIS(char *);
void main(int ac, char *av[]) {
  char buffer[BUFSIZ];
  int mode = 1;
  if (ac == 2) {
    if (!strcmp(av[1], "-e"))
      mode = 2;
    if (!strcmp(av[1], "-s"))
      mode = 3;
  }
  while (fgets(buffer, BUFSIZ, stdin) != NULL) {
    switch (mode) {
    case 2:
      printf("%s", toStringEUC(buffer));
      break;
    case 3:
      printf("%s", toStringSJIS(buffer));
      break;
    default:
      printf("%s", toStringJIS(buffer));
      break;
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x2,-0x4(%rbp)
jne    1209 <main+0x99>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe35(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11e0 <main+0x70>
movl   $0x2,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe14(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1204 <main+0x94>
movl   $0x3,-0x24(%rbp)
jmp    1209 <main+0x99>
jmp    120e <main+0x9e>
mov    -0x30(%rbp),%rdi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
mov    0x2dc6(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12af <main+0x13f>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x2,%eax
je     1258 <main+0xe8>
jmp    1247 <main+0xd7>
mov    -0x34(%rbp),%eax
sub    $0x3,%eax
je     1275 <main+0x105>
jmp    1292 <main+0x122>
mov    -0x30(%rbp),%rdi
call   1090 <toStringEUC@plt>
mov    %rax,%rsi
lea    0xd9b(%rip),%rdi
call   1040 <printf@plt>
jmp    12aa <main+0x13a>
mov    -0x30(%rbp),%rdi
call   1030 <toStringSJIS@plt>
mov    %rax,%rsi
lea    0xd7e(%rip),%rdi
call   1040 <printf@plt>
jmp    12aa <main+0x13a>
mov    -0x30(%rbp),%rdi
call   1070 <toStringJIS@plt>
mov    %rax,%rsi
lea    0xd61(%rip),%rdi
call   1040 <printf@plt>
jmp    120e <main+0x9e>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e53(%rip),%r12
mov    (%r12),%r14d
mov    %rsp,%r13
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    $0x1,%ebx
cmp    $0x2,%edi
jne    11e1 <main+0x71>
mov    0x8(%rsi),%rbx
lea    0xe4e(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
cmp    $0x1,%eax
mov    $0x1,%r15d
adc    $0x0,%r15d
lea    0xe35(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
mov    $0x3,%ebx
cmovne %r15d,%ebx
mov    0x2e00(%rip),%r15
mov    (%r15),%edx
mov    %r13,%rdi
mov    %r14d,%esi
call   1050 <fgets@plt>
test   %rax,%rax
jne    1202 <main+0x92>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xdfd(%rip),%r14
jmp    1234 <main+0xc4>
nopl   0x0(%rax,%rax,1)
call   1070 <toStringJIS@plt>
mov    %rax,%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    (%r12),%esi
mov    (%r15),%edx
mov    %r13,%rdi
call   1050 <fgets@plt>
test   %rax,%rax
je     11fb <main+0x8b>
mov    %r13,%rdi
cmp    $0x3,%ebx
je     1250 <main+0xe0>
cmp    $0x2,%ebx
jne    1210 <main+0xa0>
call   1090 <toStringEUC@plt>
jmp    1215 <main+0xa5>
nopl   0x0(%rax,%rax,1)
call   1030 <toStringSJIS@plt>
jmp    1215 <main+0xa5>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [3 x i8] c"-e\00"
@.str.1 = [3 x i8] c"-s\00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%s\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* @BUFSIZ
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
store i32 1, i32* %7
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %29
14: ; preds = %2
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strcmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %14
store i32 2, i32* %7
br label %21
21: ; preds = %20, %14
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @strcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %21
store i32 3, i32* %7
br label %28
28: ; preds = %27, %21
br label %29
29: ; preds = %28, %2
br label %30
30: ; preds = %46, %29
%31 = load i32, i32* @BUFSIZ
%32 = load i32, i32* @stdin
%33 = call i32* @fgets(i8* %11, i32 %31, i32 %32)
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %47
35: ; preds = %30
%36 = load i32, i32* %7
switch i32 %36, label %43 [
i32 2, label %37
i32 3, label %40
]
37: ; preds = %35
%38 = call i8* @toStringEUC(i8* %11)
%39 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %38)
br label %46
40: ; preds = %35
%41 = call i8* @toStringSJIS(i8* %11)
%42 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %41)
br label %46
43: ; preds = %35
%44 = call i8* @toStringJIS(i8* %11)
%45 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %43, %40, %37
br label %30
47: ; preds = %30
%48 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [3 x i8] c"-e\00"
@.str.1 = [3 x i8] c"-s\00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%s\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp eq i32 %0, 2
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i32 2, i32 1
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i32 3, i32 %12
br label %16
16: ; preds = %7, %2
%17 = phi i32 [ 1, %2 ], [ %15, %7 ]
%18 = load i32, i32* @stdin
%19 = call i32* @fgets(i8* %5, i32 %3, i32 %18)
%20 = icmp eq i32* %19, null
br i1 %20, label %35, label %21
21: ; preds = %16, %28
switch i32 %17, label %26 [
i32 2, label %22
i32 3, label %24
]
22: ; preds = %21
%23 = call i8* @toStringEUC(i8* %5)
br label %28
24: ; preds = %21
%25 = call i8* @toStringSJIS(i8* %5)
br label %28
26: ; preds = %21
%27 = call i8* @toStringJIS(i8* %5)
br label %28
28: ; preds = %26, %24, %22
%29 = phi i8* [ %27, %26 ], [ %25, %24 ], [ %23, %22 ]
%30 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @BUFSIZ
%32 = load i32, i32* @stdin
%33 = call i32* @fgets(i8* %5, i32 %31, i32 %32)
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %21
35: ; preds = %28, %16
%36 = call i32 @exit(i32 0)
unreachable
}