#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[]) {
  assert(argc == 2);
  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)
cmpl   $0x2,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe84(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe82(%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    %rsi,%rbx
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
mov    %eax,%edi
call   1040 <assert@plt>
mov    0x8(%rbx),%rdi
lea    0xe9e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
movups 0xeab(%rip),%xmm0
movups %xmm0,0xc(%rsp)
movaps 0xe93(%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 i32, i32* %4
%11 = icmp eq i32 %10, 2
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %6
%18 = bitcast [28 x i8]* %7 to i8*
%19 = getelementptr inbounds [28 x i8], [28 x i8]* %7, i64 0, i64 0
%20 = load i32*, i32** %6
%21 = call i64 @fwrite(i8* %19, i32 1, i32 27, i32* %20)
store i64 %21, i64* %8
%22 = load i64, i64* %8
%23 = icmp eq i64 %22, 27
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32*, i32** %6
%27 = call i32 @fclose(i32* %26)
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = icmp eq i32 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
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 = icmp eq i32 %0, 2
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [28 x i8], [28 x i8]* %3, i64 0, i64 0
%11 = call i64 @fwrite(i8* %10, i32 1, i32 27, i32* %9)
%12 = icmp eq i64 %11, 27
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i32 @fclose(i32* %9)
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
ret i32 0
}