#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*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ printf(char *, char const *);
int main(int argc, const char *argv[]) {
  FILE *fout = fopen(argv[argc - 1], "w");
  printf("Wrap creating \"%s\"\n", argv[argc - 1]);
  if (fout) {
    fprintf(fout, "int foo() { return 0; }\n");
    fclose(fout);
  } else {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
je     11bd <main+0x7d>
mov    -0x18(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11c9 <main+0x89>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <main+0x90>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
movslq %edi,%rbx
mov    -0x8(%rsi,%rbx,8),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
mov    -0x8(%r15,%rbx,8),%rsi
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
test   %r14,%r14
je     119a <main+0x5a>
lea    0xe9a(%rip),%rdi
mov    $0x18,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    119f <main+0x5f>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [20 x i8] c"Wrap creating \22%s\22\0A\00"
@.str.2 = [25 x i8] c"int foo() { return 0; }\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %7, i64 %10
%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 = load i8**, i8*** %5
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %14, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32*, i32** %6
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %28
23: ; preds = %2
%24 = load i32*, i32** %6
%25 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32*, i32** %6
%27 = call i32 @fclose(i32* %26)
br label %29
28: ; preds = %2
store i32 -1, i32* %3
br label %30
29: ; preds = %23
store i32 0, i32* %3
br label %30
30: ; preds = %29, %28
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [20 x i8] c"Wrap creating \22%s\22\0A\00"
@.str.2 = [25 x i8] c"int foo() { return 0; }\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add nsw i32 %0, -1
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8*, i8** %1, i64 %4
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %5
%9 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = icmp eq i32* %7, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 24, i64 1, i32* %7)
%13 = tail call i32 @fclose(i32* %7)
br label %14
14: ; preds = %2, %11
%15 = phi i32 [ 0, %11 ], [ -1, %2 ]
ret i32 %15
}