#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 */
struct option {
  char *member_0;
  unsigned char member_3;
  int /*<<< orphan*/ *member_2;
  int /*<<< orphan*/ member_1;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt_long(int, char **, char *, struct option *, int *);
#define no_argument 128
int optind;
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
char *strerror(int /*<<< orphan*/);
int tab_to_csv(int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  static struct option long_opts[] = {{"unescape", no_argument, NULL, 'u'},
                                      {0, 0, 0, 0}};
  int opti;
  bool unescape_char = false;
  setlocale(LC_ALL, "");
  while (1) {
    int ch = getopt_long(argc, argv, "u", long_opts, &opti);
    if (-1 == ch) {
      break;
    }
    switch (ch) {
    case 'u':
      unescape_char = true;
      break;
    default:
      fprintf(stderr, "unexpected arg: %d\n", ch);
      exit(1);
    }
  }
  FILE *f;
  if (optind == argc)
    f = stdin;
  else if (optind == argc - 1) {
    f = fopen(argv[optind], "r");
    if (!f) {
      fprintf(stderr, "error opening %s: %s\n", argv[optind], strerror(errno));
      exit(1);
    }
  } else {
    fprintf(stderr, "USAGE: tab-to-csv [--unescape] [PATH]\n");
    exit(1);
  }
  return tab_to_csv(f, unescape_char);
}


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)
movl   $0x0,-0x18(%rbp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xec0(%rip),%rsi
call   1050 <setlocale@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe59(%rip),%rdx
lea    0x2ea9(%rip),%rcx
lea    -0x14(%rbp),%r8
call   1030 <getopt_long@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x1c(%rbp),%eax
jne    11d6 <main+0x66>
jmp    121c <main+0xac>
mov    -0x1c(%rbp),%eax
sub    $0x75,%eax
jne    11f3 <main+0x83>
jmp    11e7 <main+0x77>
movl   $0x1,-0x18(%rbp)
jmp    1217 <main+0xa7>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11a2 <main+0x32>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jne    1241 <main+0xd1>
mov    0x2db3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1302 <main+0x192>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    12dc <main+0x16c>
mov    -0x10(%rbp),%rax
mov    0x2d7d(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdae(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12d7 <main+0x167>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d44(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xd5b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    12fd <main+0x18d>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
lea    0xd4b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1302 <main+0x192>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1060 <tab_to_csv@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xecd(%rip),%rsi
call   1050 <setlocale@plt>
xor    %ecx,%ecx
lea    0xe6b(%rip),%r15
lea    0x2ebb(%rip),%r12
lea    0x4(%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    %ecx,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1030 <getopt_long@plt>
mov    $0x1,%ecx
cmp    $0x75,%eax
je     11b0 <main+0x40>
cmp    $0xffffffff,%eax
jne    1223 <main+0xb3>
mov    0x2e05(%rip),%r15
movslq (%r15),%rax
cmp    %ebx,%eax
jne    11ee <main+0x7e>
mov    0x2dff(%rip),%rax
mov    (%rax),%rdi
jmp    120d <main+0x9d>
add    $0xffffffff,%ebx
cmp    %ebx,%eax
jne    1246 <main+0xd6>
mov    (%r14,%rax,8),%rdi
lea    0xe1f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rdi
test   %rax,%rax
je     1267 <main+0xf7>
mov    %ebp,%esi
call   1060 <tab_to_csv@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da6(%rip),%rcx
mov    (%rcx),%edi
lea    0xdd8(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%ebx
movslq (%r15),%rax
mov    (%r14,%rax,8),%rbp
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd95(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32*, i32 }
@main.long_opts = internal global [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i8 -128, i32* null, i32 117 }, %struct.option zeroinitializer]
@.str = [9 x i8] c"unescape\00"
@LC_ALL = global i32 0
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"u\00"
@stderr = global i32 0
@.str.3 = [20 x i8] c"unexpected arg: %d\0A\00"
@optind = global i32 0
@stdin = global i32* null
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [22 x i8] c"error opening %s: %s\0A\00"
@errno = global i32 0
@.str.6 = [39 x i8] c"USAGE: tab-to-csv [--unescape] [PATH]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%10 = load i32, i32* @LC_ALL
%11 = call i32 @setlocale(i32 %10, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %2, %27
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt_long(i32 %13, i8** %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @main.long_opts, i64 0, i64 0), i32* %6)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp eq i32 -1, %16
br i1 %17, label %18, label %19
18: ; preds = %12
br label %28
19: ; preds = %12
%20 = load i32, i32* %8
switch i32 %20, label %22 [
i32 117, label %21
]
21: ; preds = %19
store i32 1, i32* %7
br label %27
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = load i32, i32* %8
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %21
br label %12
28: ; preds = %18
%29 = load i32, i32* @optind
%30 = load i32, i32* %4
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = load i32*, i32** @stdin
store i32* %33, i32** %9
br label %65
34: ; preds = %28
%35 = load i32, i32* @optind
%36 = load i32, i32* %4
%37 = sub nsw i32 %36, 1
%38 = icmp eq i32 %35, %37
br i1 %38, label %39, label %60
39: ; preds = %34
%40 = load i8**, i8*** %5
%41 = load i32, i32* @optind
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %45, i32** %9
%46 = load i32*, i32** %9
%47 = icmp ne i32* %46, null
br i1 %47, label %59, label %48
48: ; preds = %39
%49 = load i32, i32* @stderr
%50 = load i8**, i8*** %5
%51 = load i32, i32* @optind
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
%54 = load i8*, i8** %53
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %54, i8* %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %39
br label %64
60: ; preds = %34
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %59
br label %65
65: ; preds = %64, %32
%66 = load i32*, i32** %9
%67 = load i32, i32* %7
%68 = call i32 @tab_to_csv(i32* %66, i32 %67)
ret i32 %68
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32*, i32 }
@main.long_opts = internal global [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i8 -128, i32* null, i32 117 }, %struct.option zeroinitializer]
@.str = [9 x i8] c"unescape\00"
@LC_ALL = global i32 0
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"u\00"
@stderr = global i32 0
@.str.3 = [20 x i8] c"unexpected arg: %d\0A\00"
@optind = global i32 0
@stdin = global i32* null
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [22 x i8] c"error opening %s: %s\0A\00"
@errno = global i32 0
@.str.6 = [39 x i8] c"USAGE: tab-to-csv [--unescape] [PATH]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @LC_ALL
%6 = tail call i32 @setlocale(i32 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %7, %2
%8 = phi i32 [ 0, %2 ], [ 1, %7 ]
%9 = call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @main.long_opts, i64 0, i64 0), i32* %3)
switch i32 %9, label %10 [
i32 -1, label %14
i32 117, label %7
]
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %7
%15 = load i32, i32* @optind
%16 = icmp eq i32 %15, %0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = load i32*, i32** @stdin
br label %42
19: ; preds = %14
%20 = add nsw i32 %0, -1
%21 = icmp eq i32 %15, %20
br i1 %21, label %22, label %38
22: ; preds = %19
%23 = sext i32 %15 to i64
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %42
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = load i32, i32* @optind
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %1, i64 %31
%33 = load i8*, i8** %32
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %33, i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %19
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %22, %17
%43 = phi i32* [ %18, %17 ], [ %26, %22 ]
%44 = call i32 @tab_to_csv(i32* %43, i32 %8)
ret i32 %44
}