#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 st_mode;
  int /*<<< orphan*/ st_mtime;
  int /*<<< orphan*/ st_atime;
  int /*<<< orphan*/ st_gid;
  int /*<<< orphan*/ st_uid;
};

/* Variables and functions */
int S_IFMT;
int S_IFREG;
int /*<<< orphan*/ chmod(char *, int);
int /*<<< orphan*/ chown(char *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ utime(char *, struct utimbuf *);
void copymeta(char *from, char *to) {
  struct stat was;
  struct utimbuf when;
  if (stat(from, &was) != 0 || (was.st_mode & S_IFMT) != S_IFREG)
    return;
  (void)chmod(to, was.st_mode & 07777);
  (void)chown(to, was.st_uid, was.st_gid);
  when.actime = was.st_atime;
  when.modtime = was.st_mtime;
  (void)utime(to, &when);
}


x86 assembly (clang, -O0):
<copymeta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jne    1182 <copymeta+0x42>
mov    -0x28(%rbp),%eax
mov    0x2e67(%rip),%rcx
and    (%rcx),%eax
mov    0x2e6e(%rip),%rcx
cmp    (%rcx),%eax
je     1187 <copymeta+0x47>
jmp    11c1 <copymeta+0x81>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%esi
and    $0xfff,%esi
call   1060 <chmod@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1050 <chown@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <utime@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copymeta>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %rax,%rax
jne    11a3 <copymeta+0x63>
mov    0x8(%rsp),%esi
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
and    %esi,%eax
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%eax
jne    11a3 <copymeta+0x63>
and    $0xfff,%esi
mov    %rbx,%rdi
call   1060 <chmod@plt>
mov    0x14(%rsp),%edx
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
call   1050 <chown@plt>
mov    0xc(%rsp),%rax
mov    %rax,(%rsp)
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <utime@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32, i32, i32 }
%struct.utimbuf = type { i32, i32 }
@S_IFMT = global i32 0
@S_IFREG = global i32 0
define void @copymeta(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.stat
%6 = alloca %struct.utimbuf
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i64 @stat(i8* %7, %struct.stat* %5)
%9 = icmp ne i64 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %2
%11 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* @S_IFMT
%14 = and i32 %12, %13
%15 = load i32, i32* @S_IFREG
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %10, %2
br label %38
18: ; preds = %10
%19 = load i8*, i8** %4
%20 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%21 = load i32, i32* %20
%22 = and i32 %21, 4095
%23 = call i32 @chmod(i8* %19, i32 %22)
%24 = load i8*, i8** %4
%25 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 4
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 3
%28 = load i32, i32* %27
%29 = call i32 @chown(i8* %24, i32 %26, i32 %28)
%30 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 2
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %6, i32 0, i32 1
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 1
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %6, i32 0, i32 0
store i32 %34, i32* %35
%36 = load i8*, i8** %4
%37 = call i32 @utime(i8* %36, %struct.utimbuf* %6)
br label %38
38: ; preds = %18, %17
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32, i32, i32 }
%struct.utimbuf = type { i32, i32 }
@S_IFMT = global i32 0
@S_IFREG = global i32 0
define void @copymeta(i8* %0, i8* nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.utimbuf
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast %struct.utimbuf* %4 to i8*
%7 = call i64 @stat(i8* %0, %struct.stat* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %31
9: ; preds = %2
%10 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* @S_IFMT
%13 = and i32 %12, %11
%14 = load i32, i32* @S_IFREG
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %31
16: ; preds = %9
%17 = and i32 %11, 4095
%18 = call i32 @chmod(i8* %1, i32 %17)
%19 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 4
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 3
%22 = load i32, i32* %21
%23 = call i32 @chown(i8* %1, i32 %20, i32 %22)
%24 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 2
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %4, i64 0, i32 1
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %4, i64 0, i32 0
store i32 %28, i32* %29
%30 = call i32 @utime(i8* %1, %struct.utimbuf* %4)
br label %31
31: ; preds = %2, %9, %16
ret void
}