#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 *);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ warn(char *, char const *);
int write_to(const char *msg, const char *path) {
  FILE *fp = fopen(path, "w");
  if (!fp) {
    warn("failed to open %s", path);
    return 1;
  }
  fputs(msg, fp);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<write_to>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118b <write_to+0x4b>
mov    -0x18(%rbp),%rsi
lea    0xe88(%rip),%rdi
call   1030 <warn@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a8 <write_to+0x68>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xeae(%rip),%rsi
mov    %r15,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1179 <write_to+0x39>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    118d <write_to+0x4d>
lea    0xe82(%rip),%rdi
mov    %r15,%rsi
call   1030 <warn@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [18 x i8] c"failed to open %s\00"
define i32 @write_to(i8* nocapture %0, i8* %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 %5, label %7
5: ; preds = %2
%6 = tail call i32 @warn(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %10
7: ; preds = %2
%8 = tail call i32 @fputs(i8* %0, i32* %3)
%9 = tail call i32 @fclose(i32* %3)
br label %10
10: ; preds = %7, %5
%11 = phi i32 [ 0, %7 ], [ 1, %5 ]
ret i32 %11
}