#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 utimbuf {
  scalar_t__ modtime;
  scalar_t__ actime;
};
struct timeval {
  long tv_usec;
  long tv_sec;
};

/* Variables and functions */
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int utimes(char const *, struct timeval *);
int utime(const char *file, const struct utimbuf *times) {
  struct timeval timevals[2];
  if (times != NULL) {
    timevals[0].tv_usec = 0L;
    timevals[1].tv_usec = 0L;
    timevals[0].tv_sec = (long int)times->actime;
    timevals[1].tv_sec = (long int)times->modtime;
  } else {
    if (gettimeofday(&timevals[0], NULL) < 0) {
      return -1;
    }
    timevals[1] = timevals[0];
  }
  return utimes(file, timevals);
}


x86 assembly (clang, -O0):
<utime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1167 <utime+0x47>
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    119a <utime+0x7a>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
jge    118a <utime+0x6a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <utime+0x8a>
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1040 <utimes@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utime>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
test   %rsi,%rsi
je     1151 <utime+0x31>
movq   $0x0,(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x8(%rsi),%rax
mov    %rax,0x8(%rsp)
mov    (%rsi),%rax
mov    %rax,0x18(%rsp)
jmp    1169 <utime+0x49>
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
js     117a <utime+0x5a>
movaps (%rsp),%xmm0
movaps %xmm0,0x10(%rsp)
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1040 <utimes@plt>
add    $0x20,%rsp
pop    %rbx
ret
mov    $0xffffffff,%eax
jmp    1174 <utime+0x54>

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

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