#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 stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
scalar_t__ remove(char *);
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(int argc, char **argv, char **envp) {
  int fd;
  char *new_name_file = "test_remove";
  struct stat statbuf;
  if (argc < 2) {
    fprintf(stderr, "Uso: %s <filename>\nfilename da eliminare\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((fd = open(argv[1], O_RDONLY)) < 0) {
    fprintf(stderr, "Err.:(%d) - %s: %s\n", errno, strerror(errno), argv[1]);
    exit(EXIT_FAILURE);
  }
  sleep(5);
  if (rename(argv[1], new_name_file) < 0) {
    fprintf(stderr, "Err.:(%d) - %s: %s\n", errno, strerror(errno), argv[1]);
    exit(EXIT_FAILURE);
  }
  sleep(5);
  if (remove(new_name_file) < 0) {
    fprintf(stderr, "Err.:(%d) - %s: %s\n", errno, strerror(errno),
            new_name_file);
    exit(EXIT_FAILURE);
  }
  close(fd);
  return (EXIT_SUCCESS);
}


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    %rdx,-0x18(%rbp)
lea    0xe5f(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11db <main+0x5b>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1250 <main+0xd0>
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <rename@plt>
cmp    $0x0,%rax
jge    12c8 <main+0x148>
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2d48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    -0x3c(%rbp),%edx
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8
lea    0xd83(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    -0x28(%rbp),%rdi
call   1030 <remove@plt>
cmp    $0x0,%rax
jge    1334 <main+0x1b4>
mov    0x2cec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2cd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%edx
mov    %rax,%rcx
mov    -0x28(%rbp),%r8
lea    0xd17(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2c9b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    0x2c7d(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x1,%edi
jle    1221 <main+0xa1>
mov    0x8(%rbx),%rdi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11f7 <main+0x77>
mov    %eax,%ebp
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    0x8(%rbx),%rdi
lea    0xe43(%rip),%rsi
call   1070 <rename@plt>
test   %rax,%rax
js     11f7 <main+0x77>
mov    $0x5,%edi
call   10a0 <sleep@plt>
lea    0xe28(%rip),%rdi
call   1030 <remove@plt>
test   %rax,%rax
js     123d <main+0xbd>
mov    %ebp,%edi
call   1040 <close@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dda(%rip),%rax
mov    (%rax),%r14d
mov    0x2dc8(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
mov    0x8(%rbx),%r8
lea    0xe1a(%rip),%rsi
mov    %r14d,%edi
jmp    1266 <main+0xe6>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdd8(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1272 <main+0xf2>
mov    0x2d94(%rip),%rax
mov    (%rax),%ebx
mov    0x2d83(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xdd9(%rip),%rsi
lea    0xd9c(%rip),%r8
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [12 x i8] c"test_remove\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"Uso: %s <filename>\0Afilename da eliminare\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [20 x i8] c"Err.:(%d) - %s: %s\0A\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8*
%10 = alloca %struct.stat
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %9
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %21
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %6
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %3
%22 = load i8**, i8*** %6
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %8
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %21
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = load i8**, i8*** %6
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %30, i8* %32, i8* %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %21
%40 = call i32 @sleep(i32 5)
%41 = load i8**, i8*** %6
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = load i8*, i8** %9
%45 = call i64 @rename(i8* %43, i8* %44)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %58
47: ; preds = %39
%48 = load i32, i32* @stderr
%49 = load i32, i32* @errno
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = load i8**, i8*** %6
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %49, i8* %51, i8* %54)
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %39
%59 = call i32 @sleep(i32 5)
%60 = load i8*, i8** %9
%61 = call i64 @remove(i8* %60)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %72
63: ; preds = %58
%64 = load i32, i32* @stderr
%65 = load i32, i32* @errno
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = load i8*, i8** %9
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %65, i8* %67, i8* %68)
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %58
%73 = load i32, i32* %8
%74 = call i32 @close(i32 %73)
%75 = load i32, i32* @EXIT_SUCCESS
ret i32 %75
}

LLVM IR (-O2):
@.str = [12 x i8] c"test_remove\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"Uso: %s <filename>\0Afilename da eliminare\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [20 x i8] c"Err.:(%d) - %s: %s\0A\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture readnone %2) {
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %11
5: ; preds = %3
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %3
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* %13, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = load i8*, i8** %12
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %19, i8* %20, i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %11
%26 = tail call i32 @sleep(i32 5)
%27 = load i8*, i8** %12
%28 = tail call i64 @rename(i8* %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = tail call i8* @strerror(i32 %32)
%34 = load i8*, i8** %12
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %32, i8* %33, i8* %34)
%36 = load i32, i32* @EXIT_FAILURE
%37 = tail call i32 @exit(i32 %36)
unreachable
38: ; preds = %25
%39 = tail call i32 @sleep(i32 5)
%40 = tail call i64 @remove(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %38
%43 = load i32, i32* @stderr
%44 = load i32, i32* @errno
%45 = tail call i8* @strerror(i32 %44)
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %44, i8* %45, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = tail call i32 @exit(i32 %47)
unreachable
49: ; preds = %38
%50 = tail call i32 @close(i32 %15)
%51 = load i32, i32* @EXIT_SUCCESS
ret i32 %51
}