#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 */
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fwrite(char *, int, size_t, int /*<<< orphan*/ *);
size_t strlen(char *);
void write_contents(char *path, char *contents) {
  FILE *f = fopen(path, "w");
  if (f == NULL) {
    return;
  }
  size_t len = strlen(contents);
  int offset = 0;
  do {
    int res = fwrite(contents + offset, 1, len - offset, f);
    if (res < 0) {
      return;
    }
    offset += res;
  } while (offset < len);
  if (fclose(f) < 0) {
    return;
  }
  return;
}


x86 assembly (clang, -O0):
<write_contents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1174 <write_contents+0x34>
jmp    11f2 <write_contents+0xb2>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rdx
movslq -0x24(%rbp),%rax
sub    %rax,%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    11be <write_contents+0x7e>
jmp    11f2 <write_contents+0xb2>
mov    -0x28(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     1188 <write_contents+0x48>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
jge    11ed <write_contents+0xad>
jmp    11f2 <write_contents+0xb2>
jmp    11f2 <write_contents+0xb2>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_contents>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11aa <write_contents+0x6a>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movslq %ebp,%rax
lea    (%r14,%rax,1),%rdi
mov    %rbx,%rdx
sub    %rax,%rdx
mov    $0x1,%esi
mov    %r15,%rcx
call   1060 <fwrite@plt>
test   %eax,%eax
js     11aa <write_contents+0x6a>
add    %eax,%ebp
movslq %ebp,%rax
cmp    %rax,%rbx
ja     1170 <write_contents+0x30>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
define void @write_contents(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
br label %46
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %6
store i32 0, i32* %7
br label %17
17: ; preds = %35, %14
%18 = load i8*, i8** %4
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i64, i64* %6
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = sub i64 %22, %24
%26 = load i32*, i32** %5
%27 = call i32 @fwrite(i8* %21, i32 1, i64 %25, i32* %26)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %17
br label %46
31: ; preds = %17
%32 = load i32, i32* %8
%33 = load i32, i32* %7
%34 = add nsw i32 %33, %32
store i32 %34, i32* %7
br label %35
35: ; preds = %31
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = load i64, i64* %6
%39 = icmp ult i64 %37, %38
br i1 %39, label %17, label %40
40: ; preds = %35
%41 = load i32*, i32** %5
%42 = call i64 @fclose(i32* %41)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %40
br label %46
45: ; preds = %40
br label %46
46: ; preds = %45, %44, %30, %13
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
define void @write_contents(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %20, label %5
5: ; preds = %2
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
br label %7
7: ; preds = %15, %5
%8 = phi i32 [ 0, %5 ], [ %14, %15 ]
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = sub i64 %6, %9
%12 = tail call i32 @fwrite(i8* %10, i32 1, i64 %11, i32* %3)
%13 = icmp slt i32 %12, 0
%14 = add nsw i32 %12, %8
br i1 %13, label %20, label %15
15: ; preds = %7
%16 = sext i32 %14 to i64
%17 = icmp ugt i64 %6, %16
br i1 %17, label %7, label %18
18: ; preds = %15
%19 = tail call i64 @fclose(i32* %3)
br label %20
20: ; preds = %7, %18, %2
ret void
}