#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 O_CREAT;
int O_EXCL;
int O_WRONLY;
int /*<<< orphan*/ *fopen(char *, char *);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[1]) {
  FILE *fp;
  fp = fopen("test3", "wx");
  if (fp == NULL) {
    printf("Fopen - File already exists. Cannot overwrite it.\n");
  } else {
    printf("Fopen - Opening file in write mode.\n");
  }
  int fd;
  fd = open("test34", O_CREAT | O_WRONLY | O_EXCL);
  if (fd == -1) {
    printf("Open - File already exists. Cannot overwrite it.\n");
  } else {
    printf("Open - Opening file in write mode\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1179 <main+0x49>
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
jmp    1185 <main+0x55>
lea    0xebc(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
mov    0x2e33(%rip),%rax
or     (%rax),%esi
mov    0x2e3a(%rip),%rax
or     (%rax),%esi
lea    0xeba(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11ca <main+0x9a>
lea    0xea8(%rip),%rdi
call   1030 <printf@plt>
jmp    11d6 <main+0xa6>
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
lea    0xec7(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
lea    0xf39(%rip),%rax
lea    0xebb(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    0x2e93(%rip),%rax
mov    0x2e5c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e61(%rip),%rax
or     (%rax),%esi
lea    0xe89(%rip),%rdi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
lea    0xec7(%rip),%rax
lea    0xe9e(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"test3\00"
@.str.1 = [3 x i8] c"wx\00"
@.str.2 = [51 x i8] c"Fopen - File already exists. Cannot overwrite it.\0A\00"
@.str.3 = [37 x i8] c"Fopen - Opening file in write mode.\0A\00"
@.str.4 = [7 x i8] c"test34\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_EXCL = global i32 0
@.str.5 = [50 x i8] c"Open - File already exists. Cannot overwrite it.\0A\00"
@.str.6 = [35 x i8] c"Open - Opening file in write mode\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
br label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %11
%16 = load i32, i32* @O_CREAT
%17 = load i32, i32* @O_WRONLY
%18 = or i32 %16, %17
%19 = load i32, i32* @O_EXCL
%20 = or i32 %18, %19
%21 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
br label %28
26: ; preds = %15
%27 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
br label %28
28: ; preds = %26, %24
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [6 x i8] c"test3\00"
@.str.1 = [3 x i8] c"wx\00"
@.str.4 = [7 x i8] c"test34\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_EXCL = global i32 0
@str = [36 x i8] c"Fopen - Opening file in write mode.\00"
@str.7 = [34 x i8] c"Open - Opening file in write mode\00"
@str.8 = [49 x i8] c"Open - File already exists. Cannot overwrite it.\00"
@str.9 = [50 x i8] c"Fopen - File already exists. Cannot overwrite it.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
%5 = select i1 %4, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @str.9, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0)
%6 = tail call i32 @puts(i8* dereferenceable(1) %5)
%7 = load i32, i32* @O_CREAT
%8 = load i32, i32* @O_WRONLY
%9 = or i32 %8, %7
%10 = load i32, i32* @O_EXCL
%11 = or i32 %9, %10
%12 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%13 = icmp eq i32 %12, -1
%14 = select i1 %13, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @str.7, i64 0, i64 0)
%15 = tail call i32 @puts(i8* dereferenceable(1) %14)
ret i32 0
}