#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 *, int /*<<< orphan*/);
size_t fwrite(char const *, int, size_t const, int /*<<< orphan*/ *);
int /*<<< orphan*/ genwb(char *);
size_t file_put_contents(const char *filename, const char *contents,
                         const size_t s) {
  FILE *fp;
  char wb[16];
  fp = fopen(filename, genwb(wb));
  if (fp == NULL) {
    return 0;
  }
  size_t sz = fwrite(contents, 1, s, fp);
  fclose(fp);
  return sz;
}


x86 assembly (clang, -O0):
<file_put_contents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <genwb@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118c <file_put_contents+0x4c>
movq   $0x0,-0x8(%rbp)
jmp    11b7 <file_put_contents+0x77>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_put_contents>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsp,%rdi
call   1040 <genwb@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <fopen@plt>
test   %rax,%rax
je     118c <file_put_contents+0x4c>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    118f <file_put_contents+0x4f>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @file_put_contents(i8* %0, i8* nocapture %1, i64 %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = call i32 @genwb(i8* %5)
%7 = call i32* @fopen(i8* %0, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = call i64 @fwrite(i8* %1, i32 1, i64 %2, i32* %7)
%11 = call i32 @fclose(i32* %7)
br label %12
12: ; preds = %3, %9
%13 = phi i64 [ %10, %9 ], [ 0, %3 ]
ret i64 %13
}