#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 {
  int tv_usec;
  int /*<<< orphan*/ tv_sec;
};
struct timespec {
  int tv_nsec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int AT_SYMLINK_NOFOLLOW;
int /*<<< orphan*/ dir_mutex_lock(int);
int /*<<< orphan*/ dir_mutex_unlock();
int lutimes(char const *, struct timeval *);
int utimes(char const *, struct timeval *);
int utimensat(int dirfd, const char *pathname, const struct timespec times[2],
              int flags) {
  int rc;
  struct timeval tv[2];
  tv[0].tv_sec = times[0].tv_sec;
  tv[0].tv_usec = times[0].tv_nsec / 1000;
  tv[1].tv_sec = times[1].tv_sec;
  tv[1].tv_usec = times[1].tv_nsec / 1000;
  dir_mutex_lock(dirfd);
  if (flags & AT_SYMLINK_NOFOLLOW) {
    rc = lutimes(pathname, tv);
  } else {
    rc = utimes(pathname, tv);
  }
  dir_mutex_unlock();
  return rc;
}


x86 assembly (clang, -O0):
<utimensat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <dir_mutex_lock@plt>
mov    -0x1c(%rbp),%eax
mov    0x2e41(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11bf <utimensat+0x7f>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <lutimes@plt>
mov    %eax,-0x20(%rbp)
jmp    11cf <utimensat+0x8f>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <utimes@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <dir_mutex_unlock@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utimensat>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
mov    %rsi,%rbx
mov    0x4(%rdx),%eax
mov    %eax,0x4(%rsp)
movslq (%rdx),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,(%rsp)
mov    0xc(%rdx),%eax
mov    %eax,0xc(%rsp)
movslq 0x8(%rdx),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,0x8(%rsp)
call   1030 <dir_mutex_lock@plt>
mov    0x2e45(%rip),%rax
test   %ebp,(%rax)
je     11ac <utimensat+0x6c>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <lutimes@plt>
jmp    11b7 <utimensat+0x77>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1040 <utimes@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <dir_mutex_unlock@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.timeval = type { i32, i32 }
@AT_SYMLINK_NOFOLLOW = global i32 0
define i32 @utimensat(i32 %0, i8* %1, %struct.timespec* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.timespec*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [2 x %struct.timeval]
store i32 %0, i32* %5
store i8* %1, i8** %6
store %struct.timespec* %2, %struct.timespec** %7
store i32 %3, i32* %8
%11 = load %struct.timespec*, %struct.timespec** %7
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i64 0
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %12, i32 0, i32 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %10, i64 0, i64 0
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
store i32 %14, i32* %16
%17 = load %struct.timespec*, %struct.timespec** %7
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %17, i64 0
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = sdiv i32 %20, 1000
%22 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %10, i64 0, i64 0
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load %struct.timespec*, %struct.timespec** %7
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %24, i64 1
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %10, i64 0, i64 1
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %28, i32 0, i32 1
store i32 %27, i32* %29
%30 = load %struct.timespec*, %struct.timespec** %7
%31 = getelementptr inbounds %struct.timespec, %struct.timespec* %30, i64 1
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = sdiv i32 %33, 1000
%35 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %10, i64 0, i64 1
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %35, i32 0, i32 0
store i32 %34, i32* %36
%37 = load i32, i32* %5
%38 = call i32 @dir_mutex_lock(i32 %37)
%39 = load i32, i32* %8
%40 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%41 = and i32 %39, %40
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %4
%44 = load i8*, i8** %6
%45 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %10, i64 0, i64 0
%46 = call i32 @lutimes(i8* %44, %struct.timeval* %45)
store i32 %46, i32* %9
br label %51
47: ; preds = %4
%48 = load i8*, i8** %6
%49 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %10, i64 0, i64 0
%50 = call i32 @utimes(i8* %48, %struct.timeval* %49)
store i32 %50, i32* %9
br label %51
51: ; preds = %47, %43
%52 = call i32 (...) @dir_mutex_unlock()
%53 = load i32, i32* %9
ret i32 %53
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
%struct.timeval = type { i32, i32 }
@AT_SYMLINK_NOFOLLOW = global i32 0
define i32 @utimensat(i32 %0, i8* %1, %struct.timespec* nocapture %2, i32 %3) {
%5 = alloca [2 x %struct.timeval]
%6 = bitcast [2 x %struct.timeval]* %5 to i8*
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%8 = load i32, i32* %7
%9 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %5, i64 0, i64 0
%10 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %5, i64 0, i64 0, i32 1
store i32 %8, i32* %10
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = sdiv i32 %12, 1000
%14 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %5, i64 0, i64 0, i32 0
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 1, i32 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %5, i64 0, i64 1, i32 1
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 1, i32 0
%19 = load i32, i32* %18
%20 = sdiv i32 %19, 1000
%21 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %5, i64 0, i64 1, i32 0
store i32 %20, i32* %21
%22 = tail call i32 @dir_mutex_lock(i32 %0)
%23 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%24 = and i32 %23, %3
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %4
%27 = call i32 @lutimes(i8* %1, %struct.timeval* %9)
br label %30
28: ; preds = %4
%29 = call i32 @utimes(i8* %1, %struct.timeval* %9)
br label %30
30: ; preds = %28, %26
%31 = phi i32 [ %27, %26 ], [ %29, %28 ]
%32 = call i32 (...) @dir_mutex_unlock()
ret i32 %31
}