#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 timeval {
  scalar_t__ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
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_ISGID;
int S_ISUID;
int /*<<< orphan*/ _cp_error(char const *, int /*<<< orphan*/);
scalar_t__ lchmod(char const *, int);
scalar_t__ lchown(char const *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ lutimes(char const *, struct timeval *);
int _cp_single_p(char const *dst, struct stat *st) {
  struct timeval tv[2];
  if (lchown(dst, st->st_uid, st->st_gid) != 0) {
    _cp_error(dst, 0);
    if (lchmod(dst, st->st_mode & ~(S_ISUID | S_ISGID)) != 0)
      _cp_error(dst, 0);
  } else if (lchmod(dst, st->st_mode) != 0)
    _cp_error(dst, 0);
  tv[0].tv_sec = st->st_atime;
  tv[0].tv_usec = 0;
  tv[1].tv_sec = st->st_mtime;
  tv[1].tv_usec = 0;
  if (lutimes(dst, tv) != 0)
    _cp_error(dst, 0);
  return 0;
}


x86 assembly (clang, -O0):
<_cp_single_p>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%esi
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%edx
call   1060 <lchown@plt>
cmp    $0x0,%rax
je     11bc <_cp_single_p+0x7c>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <_cp_error@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    0x2e42(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    %eax,%esi
call   1030 <lchmod@plt>
cmp    $0x0,%rax
je     11b7 <_cp_single_p+0x77>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <_cp_error@plt>
jmp    11e5 <_cp_single_p+0xa5>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1030 <lchmod@plt>
cmp    $0x0,%rax
je     11e0 <_cp_single_p+0xa0>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <_cp_error@plt>
jmp    11e5 <_cp_single_p+0xa5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <lutimes@plt>
cmp    $0x0,%rax
je     122b <_cp_single_p+0xeb>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <_cp_error@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_cp_single_p>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0xc(%rsi),%edx
mov    0x10(%rsi),%esi
call   1060 <lchown@plt>
test   %rax,%rax
je     117f <_cp_single_p+0x3f>
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <_cp_error@plt>
mov    0x2e7a(%rip),%rax
mov    0x2e63(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
not    %esi
and    (%rbx),%esi
jmp    1181 <_cp_single_p+0x41>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <lchmod@plt>
test   %rax,%rax
je     1198 <_cp_single_p+0x58>
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <_cp_error@plt>
mov    0x8(%rbx),%eax
mov    %eax,0x8(%rsp)
movq   $0x0,(%rsp)
mov    0x4(%rbx),%eax
mov    %eax,0x18(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <lutimes@plt>
test   %rax,%rax
je     11d1 <_cp_single_p+0x91>
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <_cp_error@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32, i32, i32 }
%struct.timeval = type { i64, i32 }
@S_ISUID = global i32 0
@S_ISGID = global i32 0
define i32 @_cp_single_p(i8* %0, %struct.stat* %1) {
%3 = alloca i8*
%4 = alloca %struct.stat*
%5 = alloca [2 x %struct.timeval]
store i8* %0, i8** %3
store %struct.stat* %1, %struct.stat** %4
%6 = load i8*, i8** %3
%7 = load %struct.stat*, %struct.stat** %4
%8 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 4
%9 = load i32, i32* %8
%10 = load %struct.stat*, %struct.stat** %4
%11 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 3
%12 = load i32, i32* %11
%13 = call i64 @lchown(i8* %6, i32 %9, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %33
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = call i32 @_cp_error(i8* %16, i32 0)
%18 = load i8*, i8** %3
%19 = load %struct.stat*, %struct.stat** %4
%20 = getelementptr inbounds %struct.stat, %struct.stat* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load i32, i32* @S_ISUID
%23 = load i32, i32* @S_ISGID
%24 = or i32 %22, %23
%25 = xor i32 %24, -1
%26 = and i32 %21, %25
%27 = call i64 @lchmod(i8* %18, i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %15
%30 = load i8*, i8** %3
%31 = call i32 @_cp_error(i8* %30, i32 0)
br label %32
32: ; preds = %29, %15
br label %44
33: ; preds = %2
%34 = load i8*, i8** %3
%35 = load %struct.stat*, %struct.stat** %4
%36 = getelementptr inbounds %struct.stat, %struct.stat* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call i64 @lchmod(i8* %34, i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %33
%41 = load i8*, i8** %3
%42 = call i32 @_cp_error(i8* %41, i32 0)
br label %43
43: ; preds = %40, %33
br label %44
44: ; preds = %43, %32
%45 = load %struct.stat*, %struct.stat** %4
%46 = getelementptr inbounds %struct.stat, %struct.stat* %45, i32 0, i32 2
%47 = load i32, i32* %46
%48 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %5, i64 0, i64 0
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %48, i32 0, i32 1
store i32 %47, i32* %49
%50 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %5, i64 0, i64 0
%51 = getelementptr inbounds %struct.timeval, %struct.timeval* %50, i32 0, i32 0
store i64 0, i64* %51
%52 = load %struct.stat*, %struct.stat** %4
%53 = getelementptr inbounds %struct.stat, %struct.stat* %52, i32 0, i32 1
%54 = load i32, i32* %53
%55 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %5, i64 0, i64 1
%56 = getelementptr inbounds %struct.timeval, %struct.timeval* %55, i32 0, i32 1
store i32 %54, i32* %56
%57 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %5, i64 0, i64 1
%58 = getelementptr inbounds %struct.timeval, %struct.timeval* %57, i32 0, i32 0
store i64 0, i64* %58
%59 = load i8*, i8** %3
%60 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %5, i64 0, i64 0
%61 = call i64 @lutimes(i8* %59, %struct.timeval* %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %44
%64 = load i8*, i8** %3
%65 = call i32 @_cp_error(i8* %64, i32 0)
br label %66
66: ; preds = %63, %44
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32, i32, i32 }
%struct.timeval = type { i64, i32 }
@S_ISUID = global i32 0
@S_ISGID = global i32 0
define i32 @_cp_single_p(i8* %0, %struct.stat* nocapture %1) {
%3 = alloca [2 x %struct.timeval]
%4 = bitcast [2 x %struct.timeval]* %3 to i8*
%5 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 4
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 3
%8 = load i32, i32* %7
%9 = tail call i64 @lchown(i8* %0, i32 %6, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %2
%12 = tail call i32 @_cp_error(i8* %0, i32 0)
%13 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%14 = load i32, i32* %13
%15 = load i32, i32* @S_ISUID
%16 = load i32, i32* @S_ISGID
%17 = or i32 %16, %15
%18 = xor i32 %17, -1
%19 = and i32 %14, %18
%20 = tail call i64 @lchmod(i8* %0, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %29, label %27
22: ; preds = %2
%23 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%24 = load i32, i32* %23
%25 = tail call i64 @lchmod(i8* %0, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %22, %11
%28 = tail call i32 @_cp_error(i8* %0, i32 0)
br label %29
29: ; preds = %27, %22, %11
%30 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 2
%31 = load i32, i32* %30
%32 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %3, i64 0, i64 0
%33 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %3, i64 0, i64 0, i32 1
store i32 %31, i32* %33
%34 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %3, i64 0, i64 0, i32 0
store i64 0, i64* %34
%35 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%36 = load i32, i32* %35
%37 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %3, i64 0, i64 1, i32 1
store i32 %36, i32* %37
%38 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %3, i64 0, i64 1, i32 0
store i64 0, i64* %38
%39 = call i64 @lutimes(i8* %0, %struct.timeval* %32)
%40 = icmp eq i64 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %29
%42 = call i32 @_cp_error(i8* %0, i32 0)
br label %43
43: ; preds = %41, %29
ret i32 0
}