#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 O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_usage(char *);
scalar_t__ strcmp(char *, char *);
int parse_arguments(int argc, char **argv, int *input, int *output) {
  if (argc != 3) {
    print_usage(argv[0]);
    return 0;
  }
  if (strcmp(argv[1], "-") != 0) {
    if ((*input = open(argv[1], O_RDONLY)) == -1) {
      perror("Can't open input file for reading");
      return 0;
    }
  } else {
    *input = 0;
  }
  if (strcmp(argv[2], "-") != 0) {
    if ((*output = open(argv[2], O_WRONLY | O_CREAT, 00664)) == -1) {
      perror("Can't open output file for writing");
      close(*input);
      return 0;
    }
  } else {
    *output = 1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<parse_arguments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1189 <parse_arguments+0x39>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <print_usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1281 <parse_arguments+0x131>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe68(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11eb <parse_arguments+0x9b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1050 <open@plt>
mov    -0x18(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0xffffffff,%eax
jne    11e6 <parse_arguments+0x96>
lea    0xe2d(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1281 <parse_arguments+0x131>
jmp    11f5 <parse_arguments+0xa5>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdfc(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1270 <parse_arguments+0x120>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
mov    0x2dcd(%rip),%rax
or     (%rax),%esi
mov    $0x1b4,%edx
mov    $0x0,%al
call   1050 <open@plt>
mov    -0x20(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0xffffffff,%eax
jne    126b <parse_arguments+0x11b>
lea    0xdd5(%rip),%rdi
call   1060 <perror@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1281 <parse_arguments+0x131>
jmp    127a <parse_arguments+0x12a>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_arguments>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11a6 <parse_arguments+0x56>
mov    %rcx,%r15
mov    %rdx,%r14
mov    0x8(%rbx),%rdi
lea    0xe90(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11b2 <parse_arguments+0x62>
mov    0x8(%rbx),%rdi
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <open@plt>
mov    %eax,(%r14)
cmp    $0xffffffff,%eax
jne    11b9 <parse_arguments+0x69>
lea    0xe63(%rip),%rdi
call   1060 <perror@plt>
jmp    1221 <parse_arguments+0xd1>
mov    (%rbx),%rdi
call   1070 <print_usage@plt>
xor    %ebp,%ebp
jmp    1221 <parse_arguments+0xd1>
movl   $0x0,(%r14)
mov    0x10(%rbx),%rdi
lea    0xe3c(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1215 <parse_arguments+0xc5>
mov    0x10(%rbx),%rdi
mov    0x2def(%rip),%rax
mov    0x2e18(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1b4,%edx
xor    %eax,%eax
call   1050 <open@plt>
mov    %eax,(%r15)
mov    $0x1,%ebp
cmp    $0xffffffff,%eax
jne    1221 <parse_arguments+0xd1>
lea    0xe20(%rip),%rdi
call   1060 <perror@plt>
mov    (%r14),%edi
call   1030 <close@plt>
xor    %ebp,%ebp
jmp    1221 <parse_arguments+0xd1>
movl   $0x1,(%r15)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@O_RDONLY = global i32 0
@.str.1 = [34 x i8] c"Can't open input file for reading\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.2 = [35 x i8] c"Can't open output file for writing\00"
define i32 @parse_arguments(i32 %0, i8** %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32*
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %4
%13 = load i8**, i8*** %7
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @print_usage(i8* %15)
store i32 0, i32* %5
br label %61
17: ; preds = %4
%18 = load i8**, i8*** %7
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %34
23: ; preds = %17
%24 = load i8**, i8*** %7
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDONLY
%28 = call i32 (i8*, i32, ...) @open(i8* %26, i32 %27)
%29 = load i32*, i32** %8
store i32 %28, i32* %29
%30 = icmp eq i32 %28, -1
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %61
33: ; preds = %23
br label %36
34: ; preds = %17
%35 = load i32*, i32** %8
store i32 0, i32* %35
br label %36
36: ; preds = %34, %33
%37 = load i8**, i8*** %7
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %58
42: ; preds = %36
%43 = load i8**, i8*** %7
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = load i32, i32* @O_WRONLY
%47 = load i32, i32* @O_CREAT
%48 = or i32 %46, %47
%49 = call i32 (i8*, i32, ...) @open(i8* %45, i32 %48, i32 436)
%50 = load i32*, i32** %9
store i32 %49, i32* %50
%51 = icmp eq i32 %49, -1
br i1 %51, label %52, label %57
52: ; preds = %42
%53 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%54 = load i32*, i32** %8
%55 = load i32, i32* %54
%56 = call i32 @close(i32 %55)
store i32 0, i32* %5
br label %61
57: ; preds = %42
br label %60
58: ; preds = %36
%59 = load i32*, i32** %9
store i32 1, i32* %59
br label %60
60: ; preds = %58, %57
store i32 1, i32* %5
br label %61
61: ; preds = %60, %52, %31, %12
%62 = load i32, i32* %5
ret i32 %62
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@O_RDONLY = global i32 0
@.str.1 = [34 x i8] c"Can't open input file for reading\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.2 = [35 x i8] c"Can't open output file for writing\00"
define i32 @parse_arguments(i32 %0, i8** nocapture %1, i32* nocapture %2, i32* nocapture writeonly %3) {
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = load i8*, i8** %1
%8 = tail call i32 @print_usage(i8* %7)
br label %39
9: ; preds = %4
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %9
%15 = load i8*, i8** %10
%16 = load i32, i32* @O_RDONLY
%17 = tail call i32 (i8*, i32, ...) @open(i8* %15, i32 %16)
store i32 %17, i32* %2
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %39
21: ; preds = %9
store i32 0, i32* %2
br label %22
22: ; preds = %14, %21
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = tail call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %38, label %27
27: ; preds = %22
%28 = load i8*, i8** %23
%29 = load i32, i32* @O_WRONLY
%30 = load i32, i32* @O_CREAT
%31 = or i32 %30, %29
%32 = tail call i32 (i8*, i32, ...) @open(i8* %28, i32 %31, i32 436)
store i32 %32, i32* %3
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %39
34: ; preds = %27
%35 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* %2
%37 = tail call i32 @close(i32 %36)
br label %39
38: ; preds = %22
store i32 1, i32* %3
br label %39
39: ; preds = %38, %27, %34, %19, %6
%40 = phi i32 [ 0, %6 ], [ 0, %19 ], [ 0, %34 ], [ 1, %27 ], [ 1, %38 ]
ret i32 %40
}