#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 dummy;
};
struct timespec {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ENOTSUP;
int /*<<< orphan*/ TIMESPEC_TO_TIMEVAL(struct timeval *,
                                       struct timespec const *);
int /*<<< orphan*/ errno;
int utimes(char const *, struct timeval *);
int utimensat(int dirfd, const char *pathname, const struct timespec ts[2],
              int flags) {
  int ret = -1;
  struct timeval tv[2];
  if (dirfd != 0) {
    errno = ENOTSUP;
    return -1;
  }
  TIMESPEC_TO_TIMEVAL(&tv[0], &ts[0]);
  TIMESPEC_TO_TIMEVAL(&tv[1], &ts[1]);
  ret = utimes(pathname, tv);
  return ret;
}


x86 assembly (clang, -O0):
<utimensat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1165 <utimensat+0x45>
mov    0x2e9a(%rip),%rax
mov    (%rax),%ecx
mov    0x2e81(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    119d <utimensat+0x7d>
lea    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <TIMESPEC_TO_TIMEVAL@plt>
lea    -0x28(%rbp),%rdi
add    $0x4,%rdi
mov    -0x18(%rbp),%rsi
add    $0x4,%rsi
call   1040 <TIMESPEC_TO_TIMEVAL@plt>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <utimes@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utimensat>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
je     1146 <utimensat+0x26>
mov    0x2eb4(%rip),%rax
mov    (%rax),%eax
mov    0x2e9b(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
jmp    1178 <utimensat+0x58>
mov    %rdx,%rbx
mov    %rsi,%r14
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    %rdx,%rsi
call   1040 <TIMESPEC_TO_TIMEVAL@plt>
lea    0xc(%rsp),%rdi
add    $0x4,%rbx
mov    %rbx,%rsi
call   1040 <TIMESPEC_TO_TIMEVAL@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <utimes@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
%struct.timeval = type { i32 }
@ENOTSUP = global i32 0
@errno = global i32 0
define i32 @utimensat(i32 %0, i8* %1, %struct.timespec* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.timespec*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [2 x %struct.timeval]
store i32 %0, i32* %6
store i8* %1, i8** %7
store %struct.timespec* %2, %struct.timespec** %8
store i32 %3, i32* %9
store i32 -1, i32* %10
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = load i32, i32* @ENOTSUP
store i32 %15, i32* @errno
store i32 -1, i32* %5
br label %29
16: ; preds = %4
%17 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %11, i64 0, i64 0
%18 = load %struct.timespec*, %struct.timespec** %8
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %18, i64 0
%20 = call i32 @TIMESPEC_TO_TIMEVAL(%struct.timeval* %17, %struct.timespec* %19)
%21 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %11, i64 0, i64 1
%22 = load %struct.timespec*, %struct.timespec** %8
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %22, i64 1
%24 = call i32 @TIMESPEC_TO_TIMEVAL(%struct.timeval* %21, %struct.timespec* %23)
%25 = load i8*, i8** %7
%26 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %11, i64 0, i64 0
%27 = call i32 @utimes(i8* %25, %struct.timeval* %26)
store i32 %27, i32* %10
%28 = load i32, i32* %10
store i32 %28, i32* %5
br label %29
29: ; preds = %16, %14
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
%struct.timeval = type { i32 }
@ENOTSUP = global i32 0
@errno = global i32 0
define i32 @utimensat(i32 %0, i8* nocapture %1, %struct.timespec* %2, i32 %3) {
%5 = alloca [2 x %struct.timeval]
%6 = bitcast [2 x %struct.timeval]* %5 to i8*
%7 = icmp eq i32 %0, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = load i32, i32* @ENOTSUP
store i32 %9, i32* @errno
br label %17
10: ; preds = %4
%11 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %5, i64 0, i64 0
%12 = call i32 @TIMESPEC_TO_TIMEVAL(%struct.timeval* %11, %struct.timespec* %2)
%13 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %5, i64 0, i64 1
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 1
%15 = call i32 @TIMESPEC_TO_TIMEVAL(%struct.timeval* %13, %struct.timespec* %14)
%16 = call i32 @utimes(i8* %1, %struct.timeval* %11)
br label %17
17: ; preds = %10, %8
%18 = phi i32 [ -1, %8 ], [ %16, %10 ]
ret i32 %18
}