#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*/ msg;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fwrite(char const *, int, int, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  FILE *f = fopen(argv[1], "w");
  const char msg[] = "int main(void) {return 0;}\n";
  size_t w = fwrite(msg, 1, sizeof(msg) - 1, f);
  assert(w == sizeof(msg) - 1);
  int r = fclose(f);
  assert(r == 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe9b(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    0xe9b(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe98(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe95(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe93(%rip),%eax
mov    %eax,-0x28(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1b,%edx
call   1060 <fwrite@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x1b,-0x48(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0x8(%rsi),%rdi
lea    0xeb0(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
movups 0xebd(%rip),%xmm0
movups %xmm0,0xc(%rsp)
movaps 0xea5(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x1b,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
xor    %edi,%edi
cmp    $0x1b,%rax
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@__const.main.msg = [28 x i8] c"int main(void) {return 0;}\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [28 x i8]
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = bitcast [28 x i8]* %7 to i8*
%15 = getelementptr inbounds [28 x i8], [28 x i8]* %7, i64 0, i64 0
%16 = load i32*, i32** %6
%17 = call i64 @fwrite(i8* %15, i32 1, i32 27, i32* %16)
store i64 %17, i64* %8
%18 = load i64, i64* %8
%19 = icmp eq i64 %18, 27
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32*, i32** %6
%23 = call i32 @fclose(i32* %22)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp eq i32 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@__const.main.msg = [28 x i8] c"int main(void) {return 0;}\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [28 x i8]
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [28 x i8], [28 x i8]* %3, i64 0, i64 0
%8 = call i64 @fwrite(i8* %7, i32 1, i32 27, i32* %6)
%9 = icmp eq i64 %8, 27
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = tail call i32 @fclose(i32* %6)
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
ret i32 0
}