#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 const *, char *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/ *);
size_t strlen(char *);
int writeFileS(const char *filePath, char *string) {
  FILE *f = NULL;
  size_t len;
  size_t writeStatus;
  len = strlen(string);
  f = fopen(filePath, "w");
  writeStatus = fwrite(string, 1, len, f);
  fclose(f);
  if (writeStatus != len) {
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<writeFileS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11b6 <writeFileS+0x76>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <writeFileS+0x7d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeFileS>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
lea    0xea0(%rip),%rsi
mov    %r14,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
cmp    %r15,%r14
setne  %al
neg    %eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
define i32 @writeFileS(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i64 @fwrite(i8* %1, i32 1, i64 %3, i32* %4)
%6 = tail call i32 @fclose(i32* %4)
%7 = icmp ne i64 %5, %3
%8 = sext i1 %7 to i32
ret i32 %8
}