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

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int __syscall_ret(int /*<<< orphan*/);
int utimensat(int, char const *, struct timespec *, int /*<<< orphan*/);
int __futimesat(int dirfd, const char *pathname,
                const struct timeval times[2]) {
  struct timespec ts[2];
  if (times) {
    int i;
    for (i = 0; i < 2; i++) {
      if (times[i].tv_usec >= 1000000ULL)
        return __syscall_ret(-EINVAL);
      ts[i].tv_sec = times[i].tv_sec;
      ts[i].tv_nsec = times[i].tv_usec * 1000;
    }
  }
  return utimensat(dirfd, pathname, times ? ts : 0, 0);
}


x86 assembly (clang, -O0):
<__futimesat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d0 <__futimesat+0xb0>
movl   $0x0,-0x34(%rbp)
cmpl   $0x2,-0x34(%rbp)
jge    11cb <__futimesat+0xab>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
cmpq   $0xf4240,(%rax)
jb     1183 <__futimesat+0x63>
xor    %edi,%edi
mov    0x2e6c(%rip),%rax
sub    (%rax),%edi
call   1040 <__syscall_ret@plt>
mov    %eax,-0x4(%rbp)
jmp    1216 <__futimesat+0xf6>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%ecx
movslq -0x34(%rbp),%rax
mov    %ecx,-0x2c(%rbp,%rax,8)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
imul   $0x3e8,(%rax),%rax
mov    %eax,%ecx
movslq -0x34(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1145 <__futimesat+0x25>
jmp    11d0 <__futimesat+0xb0>
mov    -0x8(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f6 <__futimesat+0xd6>
lea    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    1201 <__futimesat+0xe1>
xor    %eax,%eax
mov    %rax,-0x50(%rbp)
jmp    1201 <__futimesat+0xe1>
mov    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%edi
mov    -0x50(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <utimensat@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__futimesat>:
sub    $0x18,%rsp
test   %rdx,%rdx
je     1175 <__futimesat+0x55>
mov    (%rdx),%rax
cmp    $0xf4240,%rax
jae    1150 <__futimesat+0x30>
mov    0x8(%rdx),%ecx
mov    %ecx,0x4(%rsp)
imul   $0x3e8,%eax,%eax
mov    %eax,(%rsp)
mov    0x10(%rdx),%rax
cmp    $0xf423f,%rax
jbe    1164 <__futimesat+0x44>
mov    0x2e89(%rip),%rax
xor    %edi,%edi
sub    (%rax),%edi
add    $0x18,%rsp
jmp    1040 <__syscall_ret@plt>
mov    0x18(%rdx),%ecx
mov    %ecx,0xc(%rsp)
imul   $0x3e8,%eax,%eax
mov    %eax,0x8(%rsp)
test   %rdx,%rdx
mov    %rsp,%rax
cmove  %rdx,%rax
mov    %rax,%rdx
xor    %ecx,%ecx
call   1030 <utimensat@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
%struct.timespec = type { i32, i32 }
@EINVAL = global i32 0
define i32 @__futimesat(i32 %0, i8* %1, %struct.timeval* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.timeval*
%8 = alloca [2 x %struct.timespec]
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store %struct.timeval* %2, %struct.timeval** %7
%10 = load %struct.timeval*, %struct.timeval** %7
%11 = icmp ne %struct.timeval* %10, null
br i1 %11, label %12, label %55
12: ; preds = %3
store i32 0, i32* %9
br label %13
13: ; preds = %51, %12
%14 = load i32, i32* %9
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %54
16: ; preds = %13
%17 = load %struct.timeval*, %struct.timeval** %7
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i64 %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 0
%22 = load i64, i64* %21
%23 = icmp uge i64 %22, 1000000
br i1 %23, label %24, label %28
24: ; preds = %16
%25 = load i32, i32* @EINVAL
%26 = sub nsw i32 0, %25
%27 = call i32 @__syscall_ret(i32 %26)
store i32 %27, i32* %4
br label %66
28: ; preds = %16
%29 = load %struct.timeval*, %struct.timeval** %7
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %29, i64 %31
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %32, i32 0, i32 1
%34 = load i32, i32* %33
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %8, i64 0, i64 %36
%38 = getelementptr inbounds %struct.timespec, %struct.timespec* %37, i32 0, i32 1
store i32 %34, i32* %38
%39 = load %struct.timeval*, %struct.timeval** %7
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %39, i64 %41
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %42, i32 0, i32 0
%44 = load i64, i64* %43
%45 = mul i64 %44, 1000
%46 = trunc i64 %45 to i32
%47 = load i32, i32* %9
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %8, i64 0, i64 %48
%50 = getelementptr inbounds %struct.timespec, %struct.timespec* %49, i32 0, i32 0
store i32 %46, i32* %50
br label %51
51: ; preds = %28
%52 = load i32, i32* %9
%53 = add nsw i32 %52, 1
store i32 %53, i32* %9
br label %13
54: ; preds = %13
br label %55
55: ; preds = %54, %3
%56 = load i32, i32* %5
%57 = load i8*, i8** %6
%58 = load %struct.timeval*, %struct.timeval** %7
%59 = icmp ne %struct.timeval* %58, null
br i1 %59, label %60, label %62
60: ; preds = %55
%61 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %8, i64 0, i64 0
br label %63
62: ; preds = %55
br label %63
63: ; preds = %62, %60
%64 = phi %struct.timespec* [ %61, %60 ], [ null, %62 ]
%65 = call i32 @utimensat(i32 %56, i8* %57, %struct.timespec* %64, i32 0)
store i32 %65, i32* %4
br label %66
66: ; preds = %63, %24
%67 = load i32, i32* %4
ret i32 %67
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
%struct.timespec = type { i32, i32 }
@EINVAL = global i32 0
define i32 @__futimesat(i32 %0, i8* %1, %struct.timeval* %2) {
%4 = alloca [2 x %struct.timespec]
%5 = bitcast [2 x %struct.timespec]* %4 to i8*
%6 = icmp eq %struct.timeval* %2, null
br i1 %6, label %32, label %7
7: ; preds = %3
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%9 = load i64, i64* %8
%10 = icmp ugt i64 %9, 999999
br i1 %10, label %11, label %15
11: ; preds = %15, %7
%12 = load i32, i32* @EINVAL
%13 = sub nsw i32 0, %12
%14 = tail call i32 @__syscall_ret(i32 %13)
br label %36
15: ; preds = %7
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%17 = load i32, i32* %16
%18 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 0, i32 1
store i32 %17, i32* %18
%19 = trunc i64 %9 to i32
%20 = mul nuw nsw i32 %19, 1000
%21 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 0, i32 0
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 1, i32 0
%23 = load i64, i64* %22
%24 = icmp ugt i64 %23, 999999
br i1 %24, label %11, label %25
25: ; preds = %15
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 1, i32 1
%27 = load i32, i32* %26
%28 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 1, i32 1
store i32 %27, i32* %28
%29 = trunc i64 %23 to i32
%30 = mul nuw nsw i32 %29, 1000
%31 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 1, i32 0
store i32 %30, i32* %31
br label %32
32: ; preds = %25, %3
%33 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 0
%34 = select i1 %6, %struct.timespec* null, %struct.timespec* %33
%35 = call i32 @utimensat(i32 %0, i8* %1, %struct.timespec* %34, i32 0)
br label %36
36: ; preds = %11, %32
%37 = phi i32 [ %35, %32 ], [ %14, %11 ]
ret i32 %37
}