#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 */
struct dirent {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ list_dir(char *, int /*<<< orphan*/ *);
void file(char *generated, char *location) {
  FILE *f;
  struct dirent *ep;
  f = fopen(generated, "w");
  fprintf(f, "");
  fclose(f);
  f = fopen(generated, "a+");
  list_dir(location, f);
  fclose(f);
}


x86 assembly (clang, -O0):
<file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <list_dir@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xebf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rdi
call   1030 <fclose@plt>
lea    0xead(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <list_dir@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [2 x i8] c"w\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [3 x i8] c"a+\00"
define void @file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca %struct.dirent*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32*, i32** %5
%12 = call i32 @fclose(i32* %11)
%13 = load i8*, i8** %3
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %14, i32** %5
%15 = load i8*, i8** %4
%16 = load i32*, i32** %5
%17 = call i32 @list_dir(i8* %15, i32* %16)
%18 = load i32*, i32** %5
%19 = call i32 @fclose(i32* %18)
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"a+\00"
define void @file(i8* nocapture %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @fclose(i32* %3)
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @list_dir(i8* %1, i32* %5)
%7 = tail call i32 @fclose(i32* %5)
ret void
}