#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 mode_t;

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int open(char *, int, int);
int /*<<< orphan*/ printf(char *);
int rename(char *, char *);
int main() {
  int fd;
  int rename_result;
  mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
  char *filename = "./rename_org.txt";
  fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, mode);
  rename_result = rename(filename, "rename.txt");
  if (rename_result == -1) {
    printf("error");
  }
  printf("success");
  return rename_result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    0x2e89(%rip),%rcx
or     (%rcx),%eax
mov    0x2e70(%rip),%rcx
or     (%rcx),%eax
mov    0x2e5f(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x10(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    0x2e73(%rip),%rax
or     (%rax),%esi
mov    0x2e62(%rip),%rax
or     (%rax),%esi
mov    -0x10(%rbp),%edx
call   1040 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1050 <rename@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11c4 <main+0x94>
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e7e(%rip),%rax
or     (%rax),%edx
mov    0x2e6d(%rip),%rax
or     (%rax),%edx
mov    0x2e4c(%rip),%rax
mov    0x2e95(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e82(%rip),%rax
or     (%rax),%esi
lea    0xe89(%rip),%rbx
mov    %rbx,%rdi
call   1040 <open@plt>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1050 <rename@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11a1 <main+0x71>
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [17 x i8] c"./rename_org.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [11 x i8] c"rename.txt\00"
@.str.2 = [6 x i8] c"error\00"
@.str.3 = [8 x i8] c"success\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = load i32, i32* @S_IRUSR
%7 = load i32, i32* @S_IWUSR
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IRGRP
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IROTH
%12 = or i32 %10, %11
store i32 %12, i32* %4
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %5
%13 = load i8*, i8** %5
%14 = load i32, i32* @O_WRONLY
%15 = load i32, i32* @O_CREAT
%16 = or i32 %14, %15
%17 = load i32, i32* @O_TRUNC
%18 = or i32 %16, %17
%19 = load i32, i32* %4
%20 = call i32 @open(i8* %13, i32 %18, i32 %19)
store i32 %20, i32* %2
%21 = load i8*, i8** %5
%22 = call i32 @rename(i8* %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %0
%26 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %0
%28 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [17 x i8] c"./rename_org.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [11 x i8] c"rename.txt\00"
@.str.2 = [6 x i8] c"error\00"
@.str.3 = [8 x i8] c"success\00"
define i32 @main() {
%1 = load i32, i32* @S_IRUSR
%2 = load i32, i32* @S_IWUSR
%3 = or i32 %2, %1
%4 = load i32, i32* @S_IRGRP
%5 = or i32 %3, %4
%6 = load i32, i32* @S_IROTH
%7 = or i32 %5, %6
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_CREAT
%10 = or i32 %9, %8
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = tail call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %7)
%14 = tail call i32 @rename(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %0
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
ret i32 %14
}