#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 */
char EOF;
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int main(int argc, char *argv[]) {
  char *ofname;
  int i, b = 255, argo = 1;
  if (argc < 1) {
    printf("no argument\n");
    return 0;
  }
  if (argv[1][0] == '-') {
    printf("Switch detected\n");
    if (argv[1][1] == 'b') {
      b = atoi(argv[2]);
      printf("buffer =%i \n", b);
      if (argv[3][1] == '-' && argv[3][2] == 'o') {
        ofname = argv[4];
        argo = 5;
        if (argc < 5) {
          printf("no argument\n");
          return 0;
        }
      } else {
        argo = 3;
      }
    } else if (argv[1][1] == 'o') {
      ofname = argv[2];
      argo = 3;
    }
  } else {
    printf("Nope\n");
  }
  printf("output=%s\n", ofname);
  printf("%c\n", argv[1][2]);
  FILE *fp;
  char ch;
  for (i = argo; i < argc; i++) {
    printf("got here");
    fp = fopen(argv[i], "r");
    if (fp == NULL) {
      printf("%s: No such file or directory\n", argv[i]);
      return 0;
    }
    while ((ch = fgetc(fp)) != EOF) {
      putchar(ch);
    }
    fclose(fp);
  }
  return 0;
}


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   $0xff,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    11a8 <main+0x48>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    139d <main+0x23d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    12a4 <main+0x144>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x62,%eax
jne    1272 <main+0x112>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2d,%eax
jne    1266 <main+0x106>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movsbl 0x2(%rax),%eax
cmp    $0x6f,%eax
jne    1266 <main+0x106>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x5,-0x24(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    1261 <main+0x101>
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    139d <main+0x23d>
jmp    126d <main+0x10d>
movl   $0x3,-0x24(%rbp)
jmp    129f <main+0x13f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x6f,%eax
jne    129a <main+0x13a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x3,-0x24(%rbp)
jmp    129f <main+0x13f>
jmp    12b2 <main+0x152>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x2(%rax),%esi
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1396 <main+0x236>
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd38(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    134b <main+0x1eb>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    139d <main+0x23d>
jmp    1350 <main+0x1f0>
mov    -0x30(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x31(%rbp)
movsbl %al,%eax
mov    0x2c82(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     137f <main+0x21f>
movsbl -0x31(%rbp),%edi
call   1030 <putchar@plt>
jmp    1350 <main+0x1f0>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12e4 <main+0x184>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
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
test   %edi,%edi
jle    11c7 <main+0x57>
mov    %rsi,%r12
mov    0x8(%rsi),%rax
cmpb   $0x2d,(%rax)
jne    12bc <main+0x14c>
mov    %edi,%ebp
lea    0xeb3(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%r12),%rax
cmpb   $0x62,0x1(%rax)
jne    11d8 <main+0x68>
mov    0x10(%r12),%rdi
call   1090 <atoi@plt>
lea    0xe47(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x4,%ebp
ja     11e4 <main+0x74>
lea    0xe8d(%rip),%rdi
call   1040 <puts@plt>
jmp    12ab <main+0x13b>
lea    0x10(%r12),%rax
mov    $0x3,%ebx
jmp    11ee <main+0x7e>
lea    0x20(%r12),%rax
mov    $0x5,%ebx
mov    (%rax),%rsi
lea    0xe15(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%r12),%rax
movsbl 0x2(%rax),%esi
lea    0xe09(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    %ebp,%ebx
jae    12ab <main+0x13b>
mov    %ebx,%ebx
mov    %ebp,%r13d
lea    0xdfb(%rip),%r15
mov    0x2db7(%rip),%r14
jmp    1251 <main+0xe1>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
call   1050 <fclose@plt>
add    $0x1,%rbx
cmp    %r13,%rbx
je     12ab <main+0x13b>
lea    0xdc4(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r12,%rbx,8),%rdi
mov    %r15,%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1297 <main+0x127>
mov    %rax,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
call   1070 <fgetc@plt>
cmp    (%r14),%al
je     1240 <main+0xd0>
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    1280 <main+0x110>
mov    %ebx,%eax
mov    (%r12,%rax,8),%rsi
lea    0xd83(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd83(%rip),%rdi
call   1040 <puts@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"no argument\0A\00"
@.str.1 = [17 x i8] c"Switch detected\0A\00"
@.str.2 = [13 x i8] c"buffer =%i \0A\00"
@.str.3 = [6 x i8] c"Nope\0A\00"
@.str.4 = [11 x i8] c"output=%s\0A\00"
@.str.5 = [4 x i8] c"%c\0A\00"
@.str.6 = [9 x i8] c"got here\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [31 x i8] c"%s: No such file or directory\0A\00"
@EOF = global i8 0
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*
%11 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 255, i32* %8
store i32 1, i32* %9
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %132
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 45
br i1 %23, label %24, label %80
24: ; preds = %16
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 98
br i1 %32, label %33, label %66
33: ; preds = %24
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 3
%42 = load i8*, i8** %41
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 45
br i1 %46, label %47, label %64
47: ; preds = %33
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 3
%50 = load i8*, i8** %49
%51 = getelementptr inbounds i8, i8* %50, i64 2
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 111
br i1 %54, label %55, label %64
55: ; preds = %47
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 4
%58 = load i8*, i8** %57
store i8* %58, i8** %6
store i32 5, i32* %9
%59 = load i32, i32* %4
%60 = icmp slt i32 %59, 5
br i1 %60, label %61, label %63
61: ; preds = %55
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %132
63: ; preds = %55
br label %65
64: ; preds = %47, %33
store i32 3, i32* %9
br label %65
65: ; preds = %64, %63
br label %79
66: ; preds = %24
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 1
%69 = load i8*, i8** %68
%70 = getelementptr inbounds i8, i8* %69, i64 1
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 111
br i1 %73, label %74, label %78
74: ; preds = %66
%75 = load i8**, i8*** %5
%76 = getelementptr inbounds i8*, i8** %75, i64 2
%77 = load i8*, i8** %76
store i8* %77, i8** %6
store i32 3, i32* %9
br label %78
78: ; preds = %74, %66
br label %79
79: ; preds = %78, %65
br label %82
80: ; preds = %16
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %82
82: ; preds = %80, %79
%83 = load i8*, i8** %6
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %83)
%85 = load i8**, i8*** %5
%86 = getelementptr inbounds i8*, i8** %85, i64 1
%87 = load i8*, i8** %86
%88 = getelementptr inbounds i8, i8* %87, i64 2
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %90)
%92 = load i32, i32* %9
store i32 %92, i32* %7
br label %93
93: ; preds = %128, %82
%94 = load i32, i32* %7
%95 = load i32, i32* %4
%96 = icmp slt i32 %94, %95
br i1 %96, label %97, label %131
97: ; preds = %93
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%99 = load i8**, i8*** %5
%100 = load i32, i32* %7
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8*, i8** %99, i64 %101
%103 = load i8*, i8** %102
%104 = call i32* @fopen(i8* %103, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %104, i32** %10
%105 = load i32*, i32** %10
%106 = icmp eq i32* %105, null
br i1 %106, label %107, label %114
107: ; preds = %97
%108 = load i8**, i8*** %5
%109 = load i32, i32* %7
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i8*, i8** %108, i64 %110
%112 = load i8*, i8** %111
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %112)
store i32 0, i32* %3
br label %132
114: ; preds = %97
br label %115
115: ; preds = %122, %114
%116 = load i32*, i32** %10
%117 = call signext i8 @fgetc(i32* %116)
store i8 %117, i8* %11
%118 = sext i8 %117 to i32
%119 = load i8, i8* @EOF
%120 = sext i8 %119 to i32
%121 = icmp ne i32 %118, %120
br i1 %121, label %122, label %125
122: ; preds = %115
%123 = load i8, i8* %11
%124 = call i32 @putchar(i8 signext %123)
br label %115
125: ; preds = %115
%126 = load i32*, i32** %10
%127 = call i32 @fclose(i32* %126)
br label %128
128: ; preds = %125
%129 = load i32, i32* %7
%130 = add nsw i32 %129, 1
store i32 %130, i32* %7
br label %93
131: ; preds = %93
store i32 0, i32* %3
br label %132
132: ; preds = %131, %107, %61, %14
%133 = load i32, i32* %3
ret i32 %133
}

LLVM IR (-O2):
@.str.2 = [13 x i8] c"buffer =%i \0A\00"
@.str.4 = [11 x i8] c"output=%s\0A\00"
@.str.5 = [4 x i8] c"%c\0A\00"
@.str.6 = [9 x i8] c"got here\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [31 x i8] c"%s: No such file or directory\0A\00"
@EOF = global i8 0
@str = [5 x i8] c"Nope\00"
@str.9 = [16 x i8] c"Switch detected\00"
@str.11 = [12 x i8] c"no argument\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0))
br label %76
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 45
br i1 %10, label %11, label %34
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.9, i64 0, i64 0))
%13 = load i8*, i8** %7
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 98
%17 = getelementptr inbounds i8*, i8** %1, i64 2
br i1 %16, label %18, label %36
18: ; preds = %11
%19 = load i8*, i8** %17
%20 = tail call i32 @atoi(i8* %19)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds i8*, i8** %1, i64 3
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 45
tail call void @llvm.assume(i1 %26)
%27 = getelementptr inbounds i8, i8* %23, i64 2
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 111
tail call void @llvm.assume(i1 %29)
%30 = getelementptr inbounds i8*, i8** %1, i64 4
%31 = icmp ult i32 %0, 5
br i1 %31, label %32, label %36
32: ; preds = %18
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0))
br label %76
34: ; preds = %6
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
unreachable
36: ; preds = %11, %18
%37 = phi i32 [ 5, %18 ], [ 3, %11 ]
%38 = phi i8** [ %30, %18 ], [ %17, %11 ]
%39 = load i8*, i8** %38
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = load i8*, i8** %7
%42 = getelementptr inbounds i8, i8* %41, i64 2
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %44)
%46 = icmp ult i32 %37, %0
br i1 %46, label %47, label %76
47: ; preds = %36
%48 = zext i32 %37 to i64
%49 = zext i32 %0 to i64
br label %50
50: ; preds = %47, %72
%51 = phi i64 [ %48, %47 ], [ %74, %72 ]
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%53 = getelementptr inbounds i8*, i8** %1, i64 %51
%54 = load i8*, i8** %53
%55 = tail call i32* @fopen(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%56 = icmp eq i32* %55, null
br i1 %56, label %61, label %57
57: ; preds = %50
%58 = tail call signext i8 @fgetc(i32* %55)
%59 = load i8, i8* @EOF
%60 = icmp eq i8 %58, %59
br i1 %60, label %72, label %66
61: ; preds = %50
%62 = and i64 %51, 4294967295
%63 = getelementptr inbounds i8*, i8** %1, i64 %62
%64 = load i8*, i8** %63
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %64)
br label %76
66: ; preds = %57, %66
%67 = phi i8 [ %69, %66 ], [ %58, %57 ]
%68 = tail call i32 @putchar(i8 signext %67)
%69 = tail call signext i8 @fgetc(i32* %55)
%70 = load i8, i8* @EOF
%71 = icmp eq i8 %69, %70
br i1 %71, label %72, label %66
72: ; preds = %66, %57
%73 = tail call i32 @fclose(i32* %55)
%74 = add nuw nsw i64 %51, 1
%75 = icmp eq i64 %74, %49
br i1 %75, label %76, label %50
76: ; preds = %72, %36, %61, %32, %4
ret i32 0
}