#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
short int writeOnFile(char *filePath, char *contents, short int overwrite) {
  if (!filePath)
    return 0;
  FILE *myFile = 0;
  if (overwrite)
    myFile = fopen(filePath, "w");
  else
    myFile = fopen(filePath, "w+");
  if (myFile) {
    fputs(contents, myFile);
    fclose(myFile);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<writeOnFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dx,%ax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %ax,-0x1a(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115d <writeOnFile+0x2d>
movw   $0x0,-0x2(%rbp)
jmp    11cf <writeOnFile+0x9f>
movq   $0x0,-0x28(%rbp)
cmpw   $0x0,-0x1a(%rbp)
je     1189 <writeOnFile+0x59>
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
jmp    119d <writeOnFile+0x6d>
mov    -0x10(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11c9 <writeOnFile+0x99>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <fputs@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movw   $0x1,-0x2(%rbp)
jmp    11cf <writeOnFile+0x9f>
movw   $0x0,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeOnFile>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1177 <writeOnFile+0x47>
mov    %rsi,%r14
test   %dx,%dx
lea    0xebc(%rip),%rax
lea    0xeb3(%rip),%rsi
cmove  %rax,%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1177 <writeOnFile+0x47>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <fputs@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%ax
jmp    1179 <writeOnFile+0x49>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [3 x i8] c"w+\00"
define signext i16 @writeOnFile(i8* %0, i8* %1, i16 signext %2) {
%4 = alloca i16
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i16
%8 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i16 %2, i16* %7
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %3
store i16 0, i16* %4
br label %31
12: ; preds = %3
store i32* null, i32** %8
%13 = load i16, i16* %7
%14 = icmp ne i16 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i8*, i8** %5
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %8
br label %21
18: ; preds = %12
%19 = load i8*, i8** %5
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %8
br label %21
21: ; preds = %18, %15
%22 = load i32*, i32** %8
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i8*, i8** %6
%26 = load i32*, i32** %8
%27 = call i32 @fputs(i8* %25, i32* %26)
%28 = load i32*, i32** %8
%29 = call i32 @fclose(i32* %28)
store i16 1, i16* %4
br label %31
30: ; preds = %21
store i16 0, i16* %4
br label %31
31: ; preds = %30, %24, %11
%32 = load i16, i16* %4
ret i16 %32
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [3 x i8] c"w+\00"
define signext i16 @writeOnFile(i8* %0, i8* nocapture %1, i16 signext %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %13, label %5
5: ; preds = %3
%6 = icmp eq i16 %2, 0
%7 = select i1 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%8 = tail call i32* @fopen(i8* %0, i8* %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = tail call i32 @fputs(i8* %1, i32* %8)
%12 = tail call i32 @fclose(i32* %8)
br label %13
13: ; preds = %10, %5, %3
%14 = phi i16 [ 0, %3 ], [ 1, %10 ], [ 0, %5 ]
ret i16 %14
}