#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
FILE *openFile(char *path, char *fileName, char *rw) {
  FILE *fp;
  char fullPathName[1000];
  strcpy(fullPathName, path);
  strcat(fullPathName, fileName);
  if (!strcmp(rw, "rb")) {
    fp = fopen(fullPathName, "rb");
    if (fp == NULL) {
      fprintf(stderr, "Error opening file %s\n", fullPathName);
      exit(EXIT_FAILURE);
    }
  }
  if (!strcmp(rw, "wb")) {
    fp = fopen(fullPathName, "wb");
    if (fp == NULL) {
      fprintf(stderr, "Error creating %s\n", fullPathName);
      exit(EXIT_FAILURE);
    }
  }
  if (!strcmp(rw, "r")) {
    fp = fopen(fullPathName, "r");
    if (fp == NULL) {
      fprintf(stderr, "Error opening file %s\n", fullPathName);
      exit(EXIT_FAILURE);
    }
  }
  if (!strcmp(rw, "w")) {
    fp = fopen(fullPathName, "w");
    if (fp == NULL) {
      fprintf(stderr, "Error creating %s\n", fullPathName);
      exit(EXIT_FAILURE);
    }
  }
  if (!strcmp(rw, "a")) {
    fp = fopen(fullPathName, "a");
    if (fp == NULL) {
      fprintf(stderr, "Error creating %s\n", fullPathName);
      exit(EXIT_FAILURE);
    }
  }
  return fp;
}


x86 assembly (clang, -O0):
<openFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1201 <openFile+0xa1>
lea    -0x410(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11fc <openFile+0x9c>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xe1a(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1201 <openFile+0xa1>
mov    -0x18(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    126b <openFile+0x10b>
lea    -0x410(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1266 <openFile+0x106>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xdca(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    126b <openFile+0x10b>
mov    -0x18(%rbp),%rdi
lea    0xdba(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    12d5 <openFile+0x175>
lea    -0x410(%rbp),%rdi
lea    0xd9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12d0 <openFile+0x170>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xd46(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    12d5 <openFile+0x175>
mov    -0x18(%rbp),%rdi
lea    0xd52(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    133f <openFile+0x1df>
lea    -0x410(%rbp),%rdi
lea    0xd36(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    133a <openFile+0x1da>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xcf6(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    133f <openFile+0x1df>
mov    -0x18(%rbp),%rdi
lea    0xcea(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    13a9 <openFile+0x249>
lea    -0x410(%rbp),%rdi
lea    0xcce(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    13a4 <openFile+0x244>
mov    0x2c5f(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xc8c(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2c3b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    13a9 <openFile+0x249>
mov    -0x20(%rbp),%rax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openFile>:
push   %r15
push   %r14
push   %rbx
sub    $0x3f0,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rsi
mov    %rsp,%r15
mov    %r15,%rdi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <strcat@plt>
lea    0xe6e(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    11b9 <openFile+0x59>
lea    0xe5b(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1287 <openFile+0x127>
lea    0xe5a(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    11e7 <openFile+0x87>
lea    0xe47(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1275 <openFile+0x115>
lea    0xe42(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    1211 <openFile+0xb1>
lea    0xe2f(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1287 <openFile+0x127>
lea    0xe1a(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    123b <openFile+0xdb>
lea    0xe07(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1275 <openFile+0x115>
lea    0xdf2(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    1265 <openFile+0x105>
lea    0xddf(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1275 <openFile+0x115>
mov    %rbx,%rax
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
jmp    1297 <openFile+0x137>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xd6c(%rip),%rsi
mov    %rsp,%rdx
call   1050 <fprintf@plt>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Error opening file %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [19 x i8] c"Error creating %s\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [2 x i8] c"a\00"
define i32* @openFile(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [1000 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%13 = load i8*, i8** %5
%14 = call i32 @strcat(i8* %12, i8* %13)
%15 = load i8*, i8** %6
%16 = call i32 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %30, label %18
18: ; preds = %3
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %18
br label %30
30: ; preds = %29, %3
%31 = load i8*, i8** %6
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %46, label %34
34: ; preds = %30
%35 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %36, i32** %7
%37 = load i32*, i32** %7
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %45
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %34
br label %46
46: ; preds = %45, %30
%47 = load i8*, i8** %6
%48 = call i32 @strcmp(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%49 = icmp ne i32 %48, 0
br i1 %49, label %62, label %50
50: ; preds = %46
%51 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%52 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %52, i32** %7
%53 = load i32*, i32** %7
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %61
55: ; preds = %50
%56 = load i32, i32* @stderr
%57 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%58 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %57)
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %50
br label %62
62: ; preds = %61, %46
%63 = load i8*, i8** %6
%64 = call i32 @strcmp(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%65 = icmp ne i32 %64, 0
br i1 %65, label %78, label %66
66: ; preds = %62
%67 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%68 = call i32* @fopen(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %68, i32** %7
%69 = load i32*, i32** %7
%70 = icmp eq i32* %69, null
br i1 %70, label %71, label %77
71: ; preds = %66
%72 = load i32, i32* @stderr
%73 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%74 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %73)
%75 = load i32, i32* @EXIT_FAILURE
%76 = call i32 @exit(i32 %75)
unreachable
77: ; preds = %66
br label %78
78: ; preds = %77, %62
%79 = load i8*, i8** %6
%80 = call i32 @strcmp(i8* %79, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%81 = icmp ne i32 %80, 0
br i1 %81, label %94, label %82
82: ; preds = %78
%83 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%84 = call i32* @fopen(i8* %83, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %84, i32** %7
%85 = load i32*, i32** %7
%86 = icmp eq i32* %85, null
br i1 %86, label %87, label %93
87: ; preds = %82
%88 = load i32, i32* @stderr
%89 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%90 = call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %89)
%91 = load i32, i32* @EXIT_FAILURE
%92 = call i32 @exit(i32 %91)
unreachable
93: ; preds = %82
br label %94
94: ; preds = %93, %78
%95 = load i32*, i32** %7
ret i32* %95
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Error opening file %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [19 x i8] c"Error creating %s\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [2 x i8] c"a\00"
define noalias i32* @openFile(i8* %0, i8* %1, i8* nocapture %2) {
%4 = alloca [1000 x i8]
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* %0)
%7 = call i32 @strcat(i8* %5, i8* %1)
%8 = call i32 @strcmp(i8* dereferenceable(1) %2, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %3
%11 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %10, %3
%19 = phi i32* [ undef, %3 ], [ %11, %10 ]
%20 = call i32 @strcmp(i8* dereferenceable(1) %2, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %22, %18
%31 = phi i32* [ %19, %18 ], [ %23, %22 ]
%32 = call i32 @strcmp(i8* dereferenceable(1) %2, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %30
%35 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %34, %30
%43 = phi i32* [ %31, %30 ], [ %35, %34 ]
%44 = call i32 @strcmp(i8* dereferenceable(1) %2, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %42
%47 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %54
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %46, %42
%55 = phi i32* [ %43, %42 ], [ %47, %46 ]
%56 = call i32 @strcmp(i8* dereferenceable(1) %2, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %66
58: ; preds = %54
%59 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %66
61: ; preds = %58
%62 = load i32, i32* @stderr
%63 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @exit(i32 %64)
unreachable
66: ; preds = %58, %54
%67 = phi i32* [ %55, %54 ], [ %59, %58 ]
ret i32* %67
}