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

/* Variables and functions */
int /*<<< orphan*/ dec(int /*<<< orphan*/ *);
int /*<<< orphan*/ enc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getopt_long(int, char **, char *, struct option *, int *);
int optind;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  char *file;
  FILE *fp;
  int decode = 0;
  for (;;) {
    int c;
    int opt_index = 0;
    static struct option opt_long[] = {{"decode", 0, 0, 'd'}, {0, 0, 0, 0}};
    if ((c = getopt_long(argc, argv, "d", opt_long, &opt_index)) == -1) {
      break;
    }
    switch (c) {
    case 'd':
      decode = 1;
      break;
    }
  }
  if (optind >= argc) {
    fp = stdin;
  } else if (optind + 1 == argc) {
    file = argv[optind];
    if (strcmp(file, "-") == 0) {
      fp = stdin;
    } else if ((fp = fopen(file, "rb")) == NULL) {
      printf("cannot open %s\n", file);
      return 1;
    }
  } else {
    printf("Usage: %s <file>\n", argv[0]);
    return 1;
  }
  return (decode) ? !dec(fp) : !enc(fp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe75(%rip),%rdx
lea    0x2ec7(%rip),%rcx
lea    -0x2c(%rbp),%r8
call   1050 <getopt_long@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    11b3 <main+0x53>
jmp    11d0 <main+0x70>
mov    -0x28(%rbp),%eax
sub    $0x64,%eax
jne    11cb <main+0x6b>
jmp    11c4 <main+0x64>
movl   $0x1,-0x24(%rbp)
jmp    117d <main+0x1d>
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     11f5 <main+0x95>
mov    0x2dff(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    12b5 <main+0x155>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jne    1291 <main+0x131>
mov    -0x10(%rbp),%rax
mov    0x2dcb(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdde(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    124d <main+0xed>
mov    0x2da7(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    128c <main+0x12c>
mov    -0x18(%rbp),%rdi
lea    0xdb3(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1287 <main+0x127>
mov    -0x18(%rbp),%rsi
lea    0xd98(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fc <main+0x19c>
jmp    128c <main+0x12c>
jmp    12b0 <main+0x150>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd7f(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fc <main+0x19c>
jmp    12b5 <main+0x155>
cmpl   $0x0,-0x24(%rbp)
je     12dd <main+0x17d>
mov    -0x20(%rbp),%rdi
call   1040 <dec@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x30(%rbp)
jmp    12f6 <main+0x196>
mov    -0x20(%rbp),%rdi
call   1030 <enc@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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,%rbx
mov    %edi,%ebp
xor    %r13d,%r13d
lea    0xe8d(%rip),%r14
lea    0x2edf(%rip),%r15
lea    0x4(%rsp),%r12
jmp    1196 <main+0x36>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%r13d
movl   $0x0,0x4(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1050 <getopt_long@plt>
cmp    $0x64,%eax
je     1190 <main+0x30>
cmp    $0xffffffff,%eax
jne    1196 <main+0x36>
mov    0x2e1e(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    120b <main+0xab>
lea    0x1(%rax),%ecx
cmp    %ebp,%ecx
jne    122a <main+0xca>
mov    (%rbx,%rax,8),%rbx
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     120b <main+0xab>
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rdi
test   %rax,%rax
je     124d <main+0xed>
test   %r13d,%r13d
je     121a <main+0xba>
call   1040 <dec@plt>
jmp    121f <main+0xbf>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rdi
test   %r13d,%r13d
jne    1204 <main+0xa4>
call   1030 <enc@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
jmp    123e <main+0xde>
mov    (%rbx),%rsi
lea    0xdea(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdba(%rip),%rdi
mov    %rbx,%rsi
jmp    1234 <main+0xd4>

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32, i32 }
@main.opt_long = internal global [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8 0, i32 0, i32 100 }, %struct.option zeroinitializer]
@.str = [7 x i8] c"decode\00"
@.str.1 = [2 x i8] c"d\00"
@optind = global i32 0
@stdin = global i32* null
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [16 x i8] c"cannot open %s\0A\00"
@.str.5 = [18 x i8] c"Usage: %s <file>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
br label %11
11: ; preds = %20, %2
store i32 0, i32* %10
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt_long(i32 %12, i8** %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @main.opt_long, i64 0, i64 0), i32* %10)
store i32 %14, i32* %9
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %11
br label %21
17: ; preds = %11
%18 = load i32, i32* %9
switch i32 %18, label %20 [
i32 100, label %19
]
19: ; preds = %17
store i32 1, i32* %8
br label %20
20: ; preds = %17, %19
br label %11
21: ; preds = %16
%22 = load i32, i32* @optind
%23 = load i32, i32* %4
%24 = icmp sge i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i32*, i32** @stdin
store i32* %26, i32** %7
br label %58
27: ; preds = %21
%28 = load i32, i32* @optind
%29 = add nsw i32 %28, 1
%30 = load i32, i32* %4
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %52
32: ; preds = %27
%33 = load i8**, i8*** %5
%34 = load i32, i32* @optind
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
store i8* %37, i8** %6
%38 = load i8*, i8** %6
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %32
%42 = load i32*, i32** @stdin
store i32* %42, i32** %7
br label %51
43: ; preds = %32
%44 = load i8*, i8** %6
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %45, i32** %7
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i8*, i8** %6
%49 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %48)
store i32 1, i32* %3
br label %75
50: ; preds = %43
br label %51
51: ; preds = %50, %41
br label %57
52: ; preds = %27
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 0
%55 = load i8*, i8** %54
%56 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %55)
store i32 1, i32* %3
br label %75
57: ; preds = %51
br label %58
58: ; preds = %57, %25
%59 = load i32, i32* %8
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %67
61: ; preds = %58
%62 = load i32*, i32** %7
%63 = call i32 @dec(i32* %62)
%64 = icmp ne i32 %63, 0
%65 = xor i1 %64, true
%66 = zext i1 %65 to i32
br label %73
67: ; preds = %58
%68 = load i32*, i32** %7
%69 = call i32 @enc(i32* %68)
%70 = icmp ne i32 %69, 0
%71 = xor i1 %70, true
%72 = zext i1 %71 to i32
br label %73
73: ; preds = %67, %61
%74 = phi i32 [ %66, %61 ], [ %72, %67 ]
store i32 %74, i32* %3
br label %75
75: ; preds = %73, %52, %47
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32, i32 }
@main.opt_long = internal global [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8 0, i32 0, i32 100 }, %struct.option zeroinitializer]
@.str = [7 x i8] c"decode\00"
@.str.1 = [2 x i8] c"d\00"
@optind = global i32 0
@stdin = global i32* null
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [16 x i8] c"cannot open %s\0A\00"
@.str.5 = [18 x i8] c"Usage: %s <file>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %5
5: ; preds = %9, %2
%6 = phi i32 [ 0, %2 ], [ %10, %9 ]
store i32 0, i32* %3
%7 = call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @main.opt_long, i64 0, i64 0), i32* %3)
switch i32 %7, label %9 [
i32 -1, label %11
i32 100, label %8
]
8: ; preds = %5
br label %9
9: ; preds = %8, %5
%10 = phi i32 [ 1, %8 ], [ %6, %5 ]
br label %5
11: ; preds = %5
%12 = load i32, i32* @optind
%13 = icmp slt i32 %12, %0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = load i32*, i32** @stdin
br label %35
16: ; preds = %11
%17 = add nsw i32 %12, 1
%18 = icmp eq i32 %17, %0
br i1 %18, label %19, label %32
19: ; preds = %16
%20 = sext i32 %12 to i64
%21 = getelementptr inbounds i8*, i8** %1, i64 %20
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = load i32*, i32** @stdin
br label %35
27: ; preds = %19
%28 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %22)
br label %46
32: ; preds = %16
%33 = load i8*, i8** %1
%34 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %33)
br label %46
35: ; preds = %27, %25, %14
%36 = phi i32* [ %15, %14 ], [ %26, %25 ], [ %28, %27 ]
%37 = icmp eq i32 %6, 0
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = call i32 @dec(i32* %36)
br label %42
40: ; preds = %35
%41 = call i32 @enc(i32* %36)
br label %42
42: ; preds = %40, %38
%43 = phi i32 [ %39, %38 ], [ %41, %40 ]
%44 = icmp eq i32 %43, 0
%45 = zext i1 %44 to i32
br label %46
46: ; preds = %42, %32, %30
%47 = phi i32 [ %45, %42 ], [ 1, %30 ], [ 1, %32 ]
ret i32 %47
}