#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 *);
scalar_t__ fwrite(char const *, int, unsigned long, int /*<<< orphan*/ *);
int set_file_content(const char *filename, const char *content,
                     unsigned long content_size) {
  if (!filename || !content || content_size == 0) {
    return 0;
  }
  FILE *f = fopen(filename, "w");
  if (!f) {
    return 0;
  }
  int result = (int)fwrite(content, sizeof(char), content_size, f);
  fclose(f);
  return result;
}


x86 assembly (clang, -O0):
<set_file_content>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1165 <set_file_content+0x35>
cmpq   $0x0,-0x18(%rbp)
je     1165 <set_file_content+0x35>
cmpq   $0x0,-0x20(%rbp)
jne    1171 <set_file_content+0x41>
movl   $0x0,-0x4(%rbp)
jmp    11c4 <set_file_content+0x94>
mov    -0x10(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119c <set_file_content+0x6c>
movl   $0x0,-0x4(%rbp)
jmp    11c4 <set_file_content+0x94>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fwrite@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_file_content>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rdi,%rdi
je     1182 <set_file_content+0x52>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1182 <set_file_content+0x52>
mov    %rdx,%r15
test   %rdx,%rdx
je     1182 <set_file_content+0x52>
lea    0xea9(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1182 <set_file_content+0x52>
mov    %rax,%r12
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   1050 <fwrite@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r14d,%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 @set_file_content(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i64, i64* %7
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15, %12, %3
store i32 0, i32* %4
br label %34
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %8
%22 = load i32*, i32** %8
%23 = icmp ne i32* %22, null
br i1 %23, label %25, label %24
24: ; preds = %19
store i32 0, i32* %4
br label %34
25: ; preds = %19
%26 = load i8*, i8** %6
%27 = load i64, i64* %7
%28 = load i32*, i32** %8
%29 = call i64 @fwrite(i8* %26, i32 1, i64 %27, i32* %28)
%30 = trunc i64 %29 to i32
store i32 %30, i32* %9
%31 = load i32*, i32** %8
%32 = call i32 @fclose(i32* %31)
%33 = load i32, i32* %9
store i32 %33, i32* %4
br label %34
34: ; preds = %25, %24, %18
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
define i32 @set_file_content(i8* %0, i8* %1, i64 %2) {
%4 = icmp eq i8* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
%7 = icmp eq i64 %2, 0
%8 = or i1 %6, %7
br i1 %8, label %16, label %9
9: ; preds = %3
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = tail call i64 @fwrite(i8* %1, i32 1, i64 %2, i32* %10)
%14 = trunc i64 %13 to i32
%15 = tail call i32 @fclose(i32* %10)
br label %16
16: ; preds = %12, %9, %3
%17 = phi i32 [ 0, %3 ], [ %14, %12 ], [ 0, %9 ]
ret i32 %17
}