#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*/ time_t;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int /*<<< orphan*/ tm_sec;
  int /*<<< orphan*/ tm_min;
};
struct stat {
  int /*<<< orphan*/ st_gid;
  int /*<<< orphan*/ st_uid;
  int /*<<< orphan*/ st_mode;
  int /*<<< orphan*/ st_mtime;
};

/* Variables and functions */
int /*<<< orphan*/ chmod(char *, int /*<<< orphan*/);
int /*<<< orphan*/ chown(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ join_strings(char **, int, char *, char *, char *, char *);
struct tm *localtime(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
int copy_attributes(char *destination, int type, struct stat stats) {
  char *date_string;
  char *command;
  struct tm *timestamp;
  time_t mtime;
  mtime = stats.st_mtime;
  chmod(destination, stats.st_mode);
  chown(destination, stats.st_uid, stats.st_gid);
  if (type == 4)
    return 0;
  if ((date_string = (char *)malloc(18 * sizeof(char))) == NULL) {
    printf("[Error  ]\tInsufficient physical memory");
    exit(-1);
  }
  timestamp = localtime(&mtime);
  sprintf(date_string, "%d%02d%02d%02d%02d.%02d", (timestamp->tm_year + 1900),
          (timestamp->tm_mon + 1), timestamp->tm_mday, timestamp->tm_hour,
          timestamp->tm_min, timestamp->tm_sec);
  join_strings(&command, 4, "touch \"", destination, "\" -c -m -t ",
               date_string);
  system(command);
  free(date_string);
  free(command);
  return 0;
}


x86 assembly (clang, -O0):
<copy_attributes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x10(%rbp)
mov    %rdi,-0x20(%rbp)
mov    %esi,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1090 <chmod@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1080 <chown@plt>
cmpl   $0x4,-0x24(%rbp)
jne    11ee <copy_attributes+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    12bc <copy_attributes+0x11c>
mov    $0x12,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    121c <copy_attributes+0x7c>
lea    0xdf3(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
lea    -0x44(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
add    $0x76c,%edx
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%r9d
mov    -0x40(%rbp),%rax
mov    0x14(%rax),%r10d
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%eax
lea    0xdbe(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   10b0 <sprintf@plt>
mov    -0x20(%rbp),%rcx
mov    -0x30(%rbp),%r9
lea    -0x38(%rbp),%rdi
mov    $0x4,%esi
lea    0xdb1(%rip),%rdx
lea    0xdb2(%rip),%r8
call   10a0 <join_strings@plt>
mov    -0x38(%rbp),%rdi
call   1050 <system@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_attributes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbp
mov    %esi,%r14d
mov    %rdi,%r15
mov    %rdx,%rbx
shr    $0x20,%rbx
mov    %rcx,%rax
shr    $0x20,%rax
mov    %eax,0xc(%rsp)
mov    %ecx,%esi
call   1090 <chmod@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1080 <chown@plt>
cmp    $0x4,%r14d
je     1271 <copy_attributes+0xd1>
mov    $0x12,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     127e <copy_attributes+0xde>
mov    %rax,%r14
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
mov    $0x76c,%edx
add    (%rax),%edx
mov    0x4(%rax),%ecx
mov    0x8(%rax),%r8d
add    $0x1,%ecx
mov    0xc(%rax),%r9d
mov    0x14(%rax),%ebp
mov    0x10(%rax),%eax
lea    0xe03(%rip),%rsi
mov    %r14,%rdi
push   %rax
push   %rbp
call   10b0 <sprintf@plt>
add    $0x10,%rsp
lea    0xe06(%rip),%rdx
lea    0xe07(%rip),%r8
lea    0x10(%rsp),%rdi
mov    $0x4,%esi
mov    %r15,%rcx
mov    %r14,%r9
call   10a0 <join_strings@plt>
mov    0x10(%rsp),%rdi
call   1050 <system@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd7b(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32, i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [39 x i8] c"[Error ]\09Insufficient physical memory\00"
@.str.1 = [24 x i8] c"%d%02d%02d%02d%02d.%02d\00"
@.str.2 = [8 x i8] c"touch \22\00"
@.str.3 = [12 x i8] c"\22 -c -m -t \00"
define i32 @copy_attributes(i8* %0, i32 %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca %struct.stat
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca %struct.tm*
%12 = alloca i32
%13 = bitcast %struct.stat* %6 to { i64, i64 }*
%14 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %13, i32 0, i32 0
store i64 %2, i64* %14
%15 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %13, i32 0, i32 1
store i64 %3, i64* %15
store i8* %0, i8** %7
store i32 %1, i32* %8
%16 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 3
%17 = load i32, i32* %16
store i32 %17, i32* %12
%18 = load i8*, i8** %7
%19 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 2
%20 = load i32, i32* %19
%21 = call i32 @chmod(i8* %18, i32 %20)
%22 = load i8*, i8** %7
%23 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @chown(i8* %22, i32 %24, i32 %26)
%28 = load i32, i32* %8
%29 = icmp eq i32 %28, 4
br i1 %29, label %30, label %31
30: ; preds = %4
store i32 0, i32* %5
br label %71
31: ; preds = %4
%32 = call i64 @malloc(i32 18)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %9
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @exit(i32 -1)
unreachable
38: ; preds = %31
%39 = call %struct.tm* @localtime(i32* %12)
store %struct.tm* %39, %struct.tm** %11
%40 = load i8*, i8** %9
%41 = load %struct.tm*, %struct.tm** %11
%42 = getelementptr inbounds %struct.tm, %struct.tm* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = add nsw i32 %43, 1900
%45 = load %struct.tm*, %struct.tm** %11
%46 = getelementptr inbounds %struct.tm, %struct.tm* %45, i32 0, i32 1
%47 = load i32, i32* %46
%48 = add nsw i32 %47, 1
%49 = load %struct.tm*, %struct.tm** %11
%50 = getelementptr inbounds %struct.tm, %struct.tm* %49, i32 0, i32 2
%51 = load i32, i32* %50
%52 = load %struct.tm*, %struct.tm** %11
%53 = getelementptr inbounds %struct.tm, %struct.tm* %52, i32 0, i32 3
%54 = load i32, i32* %53
%55 = load %struct.tm*, %struct.tm** %11
%56 = getelementptr inbounds %struct.tm, %struct.tm* %55, i32 0, i32 5
%57 = load i32, i32* %56
%58 = load %struct.tm*, %struct.tm** %11
%59 = getelementptr inbounds %struct.tm, %struct.tm* %58, i32 0, i32 4
%60 = load i32, i32* %59
%61 = call i32 @sprintf(i8* %40, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %44, i32 %48, i32 %51, i32 %54, i32 %57, i32 %60)
%62 = load i8*, i8** %7
%63 = load i8*, i8** %9
%64 = call i32 @join_strings(i8** %10, i32 4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %62, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %63)
%65 = load i8*, i8** %10
%66 = call i32 @system(i8* %65)
%67 = load i8*, i8** %9
%68 = call i32 @free(i8* %67)
%69 = load i8*, i8** %10
%70 = call i32 @free(i8* %69)
store i32 0, i32* %5
br label %71
71: ; preds = %38, %30
%72 = load i32, i32* %5
ret i32 %72
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [39 x i8] c"[Error ]\09Insufficient physical memory\00"
@.str.1 = [24 x i8] c"%d%02d%02d%02d%02d.%02d\00"
@.str.2 = [8 x i8] c"touch \22\00"
@.str.3 = [12 x i8] c"\22 -c -m -t \00"
define i32 @copy_attributes(i8* %0, i32 %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = trunc i64 %2 to i32
%8 = lshr i64 %2, 32
%9 = trunc i64 %8 to i32
%10 = trunc i64 %3 to i32
%11 = lshr i64 %3, 32
%12 = trunc i64 %11 to i32
%13 = bitcast i8** %5 to i8*
%14 = bitcast i32* %6 to i8*
store i32 %12, i32* %6
%15 = tail call i32 @chmod(i8* %0, i32 %10)
%16 = tail call i32 @chown(i8* %0, i32 %9, i32 %7)
%17 = icmp eq i32 %1, 4
br i1 %17, label %48, label %18
18: ; preds = %4
%19 = tail call i64 @malloc(i32 18)
%20 = inttoptr i64 %19 to i8*
%21 = icmp eq i64 %19, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%24 = tail call i32 @exit(i32 -1)
unreachable
25: ; preds = %18
%26 = call %struct.tm* @localtime(i32* %6)
%27 = getelementptr inbounds %struct.tm, %struct.tm* %26, i64 0, i32 0
%28 = load i32, i32* %27
%29 = add nsw i32 %28, 1900
%30 = getelementptr inbounds %struct.tm, %struct.tm* %26, i64 0, i32 1
%31 = load i32, i32* %30
%32 = add nsw i32 %31, 1
%33 = getelementptr inbounds %struct.tm, %struct.tm* %26, i64 0, i32 2
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.tm, %struct.tm* %26, i64 0, i32 3
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.tm, %struct.tm* %26, i64 0, i32 5
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.tm, %struct.tm* %26, i64 0, i32 4
%40 = load i32, i32* %39
%41 = call i32 @sprintf(i8* %20, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %32, i32 %34, i32 %36, i32 %38, i32 %40)
%42 = call i32 @join_strings(i8** %5, i32 4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%43 = load i8*, i8** %5
%44 = call i32 @system(i8* %43)
%45 = call i32 @free(i8* %20)
%46 = load i8*, i8** %5
%47 = call i32 @free(i8* %46)
br label %48
48: ; preds = %4, %25
ret i32 0
}