#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*/ ascii2bin(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bin2ascii(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int main(int argc, char *argv[]) {
  if (argc < 4) {
    printf("The proper usage is: biconv <e/d> <infile> <outfile>. \nTo get "
           "input from stdin, use - for the infile\nTo write output to stdout, "
           "use - for the outfile\n");
    exit(0);
  } else {
    char flag = argv[1][0];
    FILE *input = stdin;
    if (*(argv[2]) != '-') {
      input = fopen(argv[2], "r");
      if (input == 0) {
        printf("Could not open file");
        exit(1);
      }
    }
    FILE *output = stdout;
    if (*(argv[3]) != '-') {
      output = fopen(argv[3], "wb");
      if (output == 0) {
        printf("Could not open outfile");
        exit(1);
      }
    }
    if (flag == 'd') {
      ascii2bin(input, output);
    } else {
      bin2ascii(input, output);
    }
    fclose(output);
    fclose(input);
  }
  exit(0);
}


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)
cmpl   $0x4,-0x8(%rbp)
jge    1193 <main+0x33>
lea    0xe79(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     1200 <main+0xa0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xec6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11fb <main+0x9b>
lea    0xead(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1200 <main+0xa0>
mov    0x2dd1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     1260 <main+0x100>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    125b <main+0xfb>
lea    0xe64(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1260 <main+0x100>
movsbl -0x11(%rbp),%eax
cmp    $0x64,%eax
jne    127f <main+0x11f>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <ascii2bin@plt>
jmp    128c <main+0x12c>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <bin2ascii@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x3,%edi
jg     118c <main+0x1c>
lea    0xeb0(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    %rsi,%rbx
mov    0x8(%rsi),%rax
mov    0x10(%rsi),%rdi
mov    (%rax),%bpl
cmpb   $0x2d,(%rdi)
jne    11ab <main+0x3b>
mov    0x2e42(%rip),%rax
mov    (%rax),%r14
jmp    11c8 <main+0x58>
lea    0xe4e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11c8 <main+0x58>
lea    0xe3c(%rip),%rdi
jmp    11f8 <main+0x88>
mov    0x18(%rbx),%rdi
cmpb   $0x2d,(%rdi)
jne    11dd <main+0x6d>
mov    0x2e00(%rip),%rax
mov    (%rax),%rbx
jmp    1207 <main+0x97>
lea    0xe32(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1207 <main+0x97>
lea    0xe21(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
cmp    $0x64,%bpl
jne    121a <main+0xaa>
call   1050 <ascii2bin@plt>
jmp    121f <main+0xaf>
call   1080 <bin2ascii@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [151 x i8] c"The proper usage is: biconv <e/d> <infile> <outfile>. \0ATo get input from stdin, use - for the infile\0ATo write output to stdout, use - for the outfile\0A\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"Could not open file\00"
@stdout = global i32* null
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [23 x i8] c"Could not open outfile\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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
store i8 %19, i8* %6
%20 = load i32*, i32** @stdin
store i32* %20, i32** %7
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 45
br i1 %26, label %27, label %38
27: ; preds = %14
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %7
%32 = load i32*, i32** %7
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %27
%35 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %27
br label %38
38: ; preds = %37, %14
%39 = load i32*, i32** @stdout
store i32* %39, i32** %8
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 3
%42 = load i8*, i8** %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 45
br i1 %45, label %46, label %57
46: ; preds = %38
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %50, i32** %8
%51 = load i32*, i32** %8
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %56
53: ; preds = %46
%54 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %46
br label %57
57: ; preds = %56, %38
%58 = load i8, i8* %6
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 100
br i1 %60, label %61, label %65
61: ; preds = %57
%62 = load i32*, i32** %7
%63 = load i32*, i32** %8
%64 = call i32 @ascii2bin(i32* %62, i32* %63)
br label %69
65: ; preds = %57
%66 = load i32*, i32** %7
%67 = load i32*, i32** %8
%68 = call i32 @bin2ascii(i32* %66, i32* %67)
br label %69
69: ; preds = %65, %61
%70 = load i32*, i32** %8
%71 = call i32 @fclose(i32* %70)
%72 = load i32*, i32** %7
%73 = call i32 @fclose(i32* %72)
br label %74
74: ; preds = %69
%75 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"Could not open file\00"
@stdout = global i32* null
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [23 x i8] c"Could not open outfile\00"
@str = [150 x i8] c"The proper usage is: biconv <e/d> <infile> <outfile>. \0ATo get input from stdin, use - for the infile\0ATo write output to stdout, use - for the outfile\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([150 x i8], [150 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = load i32*, i32** @stdin
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 45
br i1 %15, label %22, label %16
16: ; preds = %7
%17 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %16, %7
%23 = phi i32* [ %17, %16 ], [ %11, %7 ]
%24 = load i32*, i32** @stdout
%25 = getelementptr inbounds i8*, i8** %1, i64 3
%26 = load i8*, i8** %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 45
br i1 %28, label %35, label %29
29: ; preds = %22
%30 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %29, %22
%36 = phi i32* [ %30, %29 ], [ %24, %22 ]
%37 = icmp eq i8 %10, 100
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = tail call i32 @ascii2bin(i32* %23, i32* %36)
br label %42
40: ; preds = %35
%41 = tail call i32 @bin2ascii(i32* %23, i32* %36)
br label %42
42: ; preds = %40, %38
%43 = tail call i32 @fclose(i32* %36)
%44 = tail call i32 @fclose(i32* %23)
%45 = tail call i32 @exit(i32 0)
unreachable
}