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

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ inter_save(struct istruct *, char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
void inter_save_backup(struct istruct *in, char *name, int backup) {
  char wholename[200];
  char backup_file[200];
  sprintf(wholename, "%s", name);
  if (backup == 0) {
    inter_save(in, wholename);
  } else {
    sprintf(backup_file, "%s.back", name);
    if (access(wholename, F_OK) != -1) {
      remove(backup_file);
      rename(wholename, backup_file);
    }
    inter_save(in, wholename);
  }
}


x86 assembly (clang, -O0):
<inter_save_backup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe88(%rip),%rsi
call   1070 <sprintf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    119c <inter_save_backup+0x4c>
mov    -0x8(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1030 <inter_save@plt>
jmp    1200 <inter_save_backup+0xb0>
lea    -0x1b0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe55(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     11f0 <inter_save_backup+0xa0>
lea    -0x1b0(%rbp),%rdi
call   1040 <remove@plt>
lea    -0xe0(%rbp),%rdi
lea    -0x1b0(%rbp),%rsi
call   1060 <rename@plt>
mov    -0x8(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1030 <inter_save@plt>
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inter_save_backup>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1a0,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rdi
call   1050 <strcpy@plt>
test   %ebp,%ebp
je     11c7 <inter_save_backup+0x67>
lea    0xe7a(%rip),%rsi
lea    0xd0(%rsp),%rdi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1060 <access@plt>
cmp    $0xffffffff,%eax
je     11c7 <inter_save_backup+0x67>
lea    0xd0(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <remove@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1070 <rename@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <inter_save@plt>
add    $0x1a0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.istruct = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [8 x i8] c"%s.back\00"
@F_OK = global i32 0
define void @inter_save_backup(%struct.istruct* %0, i8* %1, i32 %2) {
%4 = alloca %struct.istruct*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [200 x i8]
%8 = alloca [200 x i8]
store %struct.istruct* %0, %struct.istruct** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%10 = load i8*, i8** %5
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load %struct.istruct*, %struct.istruct** %4
%16 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%17 = call i32 @inter_save(%struct.istruct* %15, i8* %16)
br label %36
18: ; preds = %3
%19 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%20 = load i8*, i8** %5
%21 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%23 = load i32, i32* @F_OK
%24 = call i32 @access(i8* %22, i32 %23)
%25 = icmp ne i32 %24, -1
br i1 %25, label %26, label %32
26: ; preds = %18
%27 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%28 = call i32 @remove(i8* %27)
%29 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%30 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%31 = call i32 @rename(i8* %29, i8* %30)
br label %32
32: ; preds = %26, %18
%33 = load %struct.istruct*, %struct.istruct** %4
%34 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%35 = call i32 @inter_save(%struct.istruct* %33, i8* %34)
br label %36
36: ; preds = %32, %14
ret void
}

LLVM IR (-O2):
%struct.istruct = type { i32 }
@.str.1 = [8 x i8] c"%s.back\00"
@F_OK = global i32 0
define void @inter_save_backup(%struct.istruct* %0, i8* %1, i32 %2) {
%4 = alloca [200 x i8]
%5 = alloca [200 x i8]
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%8 = call i8* @strcpy(i8* %6, i8* dereferenceable(1) %1)
%9 = icmp eq i32 %2, 0
br i1 %9, label %18, label %10
10: ; preds = %3
%11 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%12 = load i32, i32* @F_OK
%13 = call i32 @access(i8* %6, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = call i32 @remove(i8* %7)
%17 = call i32 @rename(i8* %6, i8* %7)
br label %18
18: ; preds = %10, %15, %3
%19 = call i32 @inter_save(%struct.istruct* %0, i8* %6)
ret void
}