#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 *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int rename(char *, char *);
int /*<<< orphan*/ *stderr;
int main(void) {
  FILE *f = fopen("tmp/foodle", "a");
  fprintf(f, "hi there!\n");
  fclose(f);
  fprintf(stderr, "about to rename\n");
  int returncode = rename("tmp/foodle", "tmp/barbaz");
  fprintf(stderr, "rename gives %d\n", returncode);
  f = fopen("tmp/silly-file", "a");
  fprintf(f, "hi there!\n");
  fclose(f);
  rename("tmp/silly-file", "tmp/silly-file");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%rdi
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    0xe60(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1060 <rename@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%edx
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    0xe74(%rip),%rdi
lea    0xe33(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe42(%rip),%rsi
mov    %rsi,%rdi
call   1060 <rename@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%r12
lea    0xea5(%rip),%r15
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xe92(%rip),%r14
mov    $0xa,%esi
mov    $0x1,%edx
mov    %r14,%rdi
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2e41(%rip),%rbx
mov    (%rbx),%rcx
lea    0xe6f(%rip),%rdi
mov    $0x10,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
lea    0xe6a(%rip),%rsi
mov    %r12,%rdi
call   1060 <rename@plt>
mov    (%rbx),%rdi
lea    0xe63(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe64(%rip),%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    $0xa,%esi
mov    $0x1,%edx
mov    %r14,%rdi
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
mov    %r12,%rsi
call   1060 <rename@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"tmp/foodle\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [11 x i8] c"hi there!\0A\00"
@stderr = global i32* null
@.str.3 = [17 x i8] c"about to rename\0A\00"
@.str.4 = [11 x i8] c"tmp/barbaz\00"
@.str.5 = [17 x i8] c"rename gives %d\0A\00"
@.str.6 = [15 x i8] c"tmp/silly-file\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32*, i32** %2
%8 = call i32 @fclose(i32* %7)
%9 = load i32*, i32** @stderr
%10 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @rename(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i32 %11, i32* %3
%12 = load i32*, i32** @stderr
%13 = load i32, i32* %3
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %13)
%15 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %2
%16 = load i32*, i32** %2
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
%20 = call i32 @rename(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"tmp/foodle\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [11 x i8] c"hi there!\0A\00"
@stderr = global i32* null
@.str.3 = [17 x i8] c"about to rename\0A\00"
@.str.4 = [11 x i8] c"tmp/barbaz\00"
@.str.5 = [17 x i8] c"rename gives %d\0A\00"
@.str.6 = [15 x i8] c"tmp/silly-file\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 10, i64 1, i32* %1)
%3 = tail call i32 @fclose(i32* %1)
%4 = load i32*, i32** @stderr
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 16, i64 1, i32* %4)
%6 = tail call i32 @rename(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%7 = load i32*, i32** @stderr
%8 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %6)
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 10, i64 1, i32* %9)
%11 = tail call i32 @fclose(i32* %9)
%12 = tail call i32 @rename(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}