#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 utimbuf {
  int /*<<< orphan*/ modtime;
  int /*<<< orphan*/ actime;
};
struct stat {
  int /*<<< orphan*/ st_mtime;
  int /*<<< orphan*/ st_atime;
};

/* Variables and functions */
int /*<<< orphan*/ copy_file(char *, char *);
int /*<<< orphan*/ free(char *);
char *generate_backup_name(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_file_stats(struct stat *);
scalar_t__ stat(char *, struct stat *);
scalar_t__ utime(char *, struct utimbuf *);
void create_backup(char *filename) {
  struct stat target_stat;
  struct utimbuf target_meta;
  char *backup_name = generate_backup_name(filename);
  if (stat(filename, &target_stat) < 0) {
    perror(filename);
  }
  print_file_stats(&target_stat);
  copy_file(filename, backup_name);
  target_meta.actime = target_stat.st_atime;
  target_meta.modtime = target_stat.st_mtime;
  if (utime(filename, &target_meta) < 0) {
    perror(filename);
  }
  free(backup_name);
}


x86 assembly (clang, -O0):
<create_backup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <generate_backup_name@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jge    11a9 <create_backup+0x39>
mov    -0x8(%rbp),%rdi
call   1090 <perror@plt>
lea    -0x10(%rbp),%rdi
call   1060 <print_file_stats@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <copy_file@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <utime@plt>
cmp    $0x0,%rax
jge    11eb <create_backup+0x7b>
mov    -0x8(%rbp),%rdi
call   1090 <perror@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_backup>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
call   1080 <generate_backup_name@plt>
mov    %rax,%r14
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <stat@plt>
test   %rax,%rax
js     11d5 <create_backup+0x65>
lea    0x8(%rsp),%rdi
call   1060 <print_file_stats@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <copy_file@plt>
mov    0x8(%rsp),%rax
mov    %rax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <utime@plt>
test   %rax,%rax
js     11df <create_backup+0x6f>
mov    %r14,%rdi
call   1040 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
call   1090 <perror@plt>
jmp    1194 <create_backup+0x24>
mov    %rbx,%rdi
call   1090 <perror@plt>
jmp    11c5 <create_backup+0x55>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
%struct.utimbuf = type { i32, i32 }
define void @create_backup(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca %struct.utimbuf
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @generate_backup_name(i8* %6)
store i8* %7, i8** %5
%8 = load i8*, i8** %2
%9 = call i64 @stat(i8* %8, %struct.stat* %3)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call i32 @perror(i8* %12)
br label %14
14: ; preds = %11, %1
%15 = call i32 @print_file_stats(%struct.stat* %3)
%16 = load i8*, i8** %2
%17 = load i8*, i8** %5
%18 = call i32 @copy_file(i8* %16, i8* %17)
%19 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %4, i32 0, i32 1
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %4, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i8*, i8** %2
%26 = call i64 @utime(i8* %25, %struct.utimbuf* %4)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %14
%29 = load i8*, i8** %2
%30 = call i32 @perror(i8* %29)
br label %31
31: ; preds = %28, %14
%32 = load i8*, i8** %5
%33 = call i32 @free(i8* %32)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
%struct.utimbuf = type { i32, i32 }
define void @create_backup(i8* %0) {
%2 = alloca %struct.stat
%3 = alloca %struct.utimbuf
%4 = bitcast %struct.stat* %2 to i8*
%5 = bitcast %struct.utimbuf* %3 to i8*
%6 = tail call i8* @generate_backup_name(i8* %0)
%7 = call i64 @stat(i8* %0, %struct.stat* %2)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* %0)
br label %11
11: ; preds = %9, %1
%12 = call i32 @print_file_stats(%struct.stat* %2)
%13 = call i32 @copy_file(i8* %0, i8* %6)
%14 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %3, i64 0, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %3, i64 0, i32 0
store i32 %18, i32* %19
%20 = call i64 @utime(i8* %0, %struct.utimbuf* %3)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %11
%23 = call i32 @perror(i8* %0)
br label %24
24: ; preds = %22, %11
%25 = call i32 @free(i8* %6)
ret void
}