#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 /*<<< orphan*/ AT_FDCWD;
int utimensat(int /*<<< orphan*/, char const *, struct timespec *,
              int /*<<< orphan*/);
int utimes(const char *path, const struct timeval tv[2]) {
  if (!tv) {
    return utimensat(AT_FDCWD, path, NULL, 0);
  }
  struct timespec ts[2];
  ts[0].tv_sec = tv[0].tv_sec;
  ts[0].tv_nsec = tv[0].tv_usec * 1000;
  ts[1].tv_sec = tv[1].tv_sec;
  ts[1].tv_nsec = tv[1].tv_usec * 1000;
  return utimensat(AT_FDCWD, path, ts, 0);
}


x86 assembly (clang, -O0):
<utimes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    114b <utimes+0x3b>
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
call   1030 <utimensat@plt>
mov    %eax,-0x4(%rbp)
jmp    1195 <utimes+0x85>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
imul   $0x3e8,(%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
imul   $0x3e8,0x8(%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
lea    -0x30(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <utimensat@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utimes>:
sub    $0x18,%rsp
mov    %rdi,%rax
test   %rsi,%rsi
je     1159 <utimes+0x49>
mov    0x4(%rsi),%ecx
mov    %ecx,0x4(%rsp)
imul   $0x3e8,(%rsi),%ecx
mov    %ecx,(%rsp)
mov    0xc(%rsi),%ecx
mov    %ecx,0xc(%rsp)
imul   $0x3e8,0x8(%rsi),%ecx
mov    %ecx,0x8(%rsp)
mov    0x2e93(%rip),%rcx
mov    (%rcx),%edi
mov    %rsp,%rdx
mov    %rax,%rsi
xor    %ecx,%ecx
call   1030 <utimensat@plt>
add    $0x18,%rsp
ret
mov    0x2e78(%rip),%rcx
mov    (%rcx),%edi
mov    %rax,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
add    $0x18,%rsp
jmp    1030 <utimensat@plt>

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

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