#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*/ debugMsg(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int writeFile(char *file, char *str) {
  debugMsg("writeFile() ...");
  FILE *fptr;
  if ((fptr = fopen(file, "w")) == NULL) {
    debugMsg("writeFile() ... fail ...");
    return 1;
  }
  fprintf(fptr, "%s", str);
  fclose(fptr);
  debugMsg("writeFile() ... ok ...");
  return 0;
}


x86 assembly (clang, -O0):
<writeFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xea9(%rip),%rdi
call   1040 <debugMsg@plt>
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1192 <writeFile+0x52>
lea    0xe91(%rip),%rdi
call   1040 <debugMsg@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c2 <writeFile+0x82>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe8a(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe78(%rip),%rdi
call   1040 <debugMsg@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeFile>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeaf(%rip),%rdi
call   1050 <debugMsg@plt>
lea    0xeb3(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     118b <writeFile+0x4b>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <fputs@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %ebx,%ebx
lea    0xea2(%rip),%rdi
jmp    1197 <writeFile+0x57>
mov    $0x1,%ebx
lea    0xe7b(%rip),%rdi
call   1050 <debugMsg@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"writeFile() ...\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [25 x i8] c"writeFile() ... fail ...\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [23 x i8] c"writeFile() ... ok ...\00"
define i32 @writeFile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = call i32 @debugMsg(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @debugMsg(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %20
13: ; preds = %2
%14 = load i32*, i32** %6
%15 = load i8*, i8** %5
%16 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = load i32*, i32** %6
%18 = call i32 @fclose(i32* %17)
%19 = call i32 @debugMsg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %20
20: ; preds = %13, %11
%21 = load i32, i32* %3
ret i32 %21
}

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