#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*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fwrite(char const *, int /*<<< orphan*/, int,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
void do_copy(const char *data, const char *path) {
  FILE *file = fopen(path, "w");
  if (file) {
    fwrite(data, strlen(data), sizeof(char), file);
    fflush(file);
    fclose(file);
  } else {
    printf("error: %s\n", strerror(errno));
  }
}


x86 assembly (clang, -O0):
<do_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11db <do_copy+0x6b>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fflush@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11f8 <do_copy+0x88>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xe0f(%rip),%rdi
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_copy>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xe7f(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c2 <do_copy+0x52>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fflush@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe2b(%rip),%rdi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printf@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [11 x i8] c"error: %s\0A\00"
@errno = global i32 0
define void @do_copy(i8* %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i32 @fwrite(i8* %0, i32 %6, i32 1, i32* %3)
%8 = tail call i32 @fflush(i32* %3)
%9 = tail call i32 @fclose(i32* %3)
br label %14
10: ; preds = %2
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %10, %5
ret void
}