#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 timespec {
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int O_CREAT;
int O_DIRECTORY;
int O_EXCL;
int O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ UTIME_NOW;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int open(char *, int);
int openat(int, char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int utimensat(int, char *, struct timespec *, int /*<<< orphan*/);
int main() {
  int tmpd = open("tmp", O_RDONLY | O_DIRECTORY);
  int subd = openat(tmpd, "subdir1", O_RDONLY | O_DIRECTORY);
  fprintf(stderr, "subd is %d\n", subd);
  openat(subd, "openat", O_WRONLY | O_CREAT | O_EXCL, 0666);
  struct timespec ts[2] = {{UTIME_NOW, UTIME_NOW}, {UTIME_NOW, UTIME_NOW}};
  int retval = utimensat(subd, "foo_symlink", ts, 0);
  if (retval < 0) {
    perror("trouble");
  }
  printf("retval was %d\n", retval);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
mov    0x2e49(%rip),%rax
or     (%rax),%esi
lea    0xe78(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
mov    0x2e25(%rip),%rax
or     (%rax),%edx
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1040 <openat@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe43(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0xc(%rbp),%edi
mov    0x2dd0(%rip),%rax
mov    (%rax),%edx
mov    0x2e17(%rip),%rax
or     (%rax),%edx
mov    0x2dce(%rip),%rax
or     (%rax),%edx
lea    0xe25(%rip),%rsi
mov    $0x1b6,%ecx
mov    $0x0,%al
call   1040 <openat@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rdx
lea    0xde2(%rip),%rsi
xor    %ecx,%ecx
call   1030 <utimensat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    125d <main+0xfd>
lea    0xdd3(%rip),%rdi
call   1080 <perror@plt>
mov    -0x24(%rbp),%esi
lea    0xdcc(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e6a(%rip),%r14
mov    0x2e53(%rip),%rbx
mov    (%rbx),%esi
or     (%r14),%esi
lea    0xe7f(%rip),%rdi
call   1070 <open@plt>
mov    (%rbx),%edx
or     (%r14),%edx
lea    0xe72(%rip),%rsi
mov    %eax,%edi
xor    %eax,%eax
call   1040 <openat@plt>
mov    %eax,%ebx
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
mov    %ebx,%edx
call   1060 <fprintf@plt>
mov    0x2ded(%rip),%rax
mov    0x2e36(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2deb(%rip),%rax
or     (%rax),%edx
lea    0xe42(%rip),%rsi
mov    %ebx,%edi
mov    $0x1b6,%ecx
xor    %eax,%eax
call   1040 <openat@plt>
mov    0x2e05(%rip),%rax
movd   (%rax),%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa %xmm0,(%rsp)
lea    0xe1f(%rip),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
xor    %ecx,%ecx
call   1030 <utimensat@plt>
mov    %eax,%ebx
test   %eax,%eax
js     122a <main+0xca>
lea    0xe1a(%rip),%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdfa(%rip),%rdi
call   1080 <perror@plt>
jmp    1212 <main+0xb2>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@.str = [4 x i8] c"tmp\00"
@O_RDONLY = global i32 0
@O_DIRECTORY = global i32 0
@.str.1 = [8 x i8] c"subdir1\00"
@stderr = global i32 0
@.str.2 = [12 x i8] c"subd is %d\0A\00"
@.str.3 = [7 x i8] c"openat\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@UTIME_NOW = global i32 0
@.str.4 = [12 x i8] c"foo_symlink\00"
@.str.5 = [8 x i8] c"trouble\00"
@.str.6 = [15 x i8] c"retval was %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x %struct.timespec]
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @O_RDONLY
%7 = load i32, i32* @O_DIRECTORY
%8 = or i32 %6, %7
%9 = call i32 @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = load i32, i32* @O_RDONLY
%12 = load i32, i32* @O_DIRECTORY
%13 = or i32 %11, %12
%14 = call i32 (i32, i8*, i32, ...) @openat(i32 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 %14, i32* %3
%15 = load i32, i32* @stderr
%16 = load i32, i32* %3
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %3
%19 = load i32, i32* @O_WRONLY
%20 = load i32, i32* @O_CREAT
%21 = or i32 %19, %20
%22 = load i32, i32* @O_EXCL
%23 = or i32 %21, %22
%24 = call i32 (i32, i8*, i32, ...) @openat(i32 %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 438)
%25 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 0
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %25, i32 0, i32 0
%27 = load i32, i32* @UTIME_NOW
store i32 %27, i32* %26
%28 = getelementptr inbounds %struct.timespec, %struct.timespec* %25, i32 0, i32 1
%29 = load i32, i32* @UTIME_NOW
store i32 %29, i32* %28
%30 = getelementptr inbounds %struct.timespec, %struct.timespec* %25, i64 1
%31 = getelementptr inbounds %struct.timespec, %struct.timespec* %30, i32 0, i32 0
%32 = load i32, i32* @UTIME_NOW
store i32 %32, i32* %31
%33 = getelementptr inbounds %struct.timespec, %struct.timespec* %30, i32 0, i32 1
%34 = load i32, i32* @UTIME_NOW
store i32 %34, i32* %33
%35 = load i32, i32* %3
%36 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 0
%37 = call i32 @utimensat(i32 %35, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), %struct.timespec* %36, i32 0)
store i32 %37, i32* %5
%38 = load i32, i32* %5
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %0
%41 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %42
42: ; preds = %40, %0
%43 = load i32, i32* %5
%44 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %43)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@.str = [4 x i8] c"tmp\00"
@O_RDONLY = global i32 0
@O_DIRECTORY = global i32 0
@.str.1 = [8 x i8] c"subdir1\00"
@stderr = global i32 0
@.str.2 = [12 x i8] c"subd is %d\0A\00"
@.str.3 = [7 x i8] c"openat\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@UTIME_NOW = global i32 0
@.str.4 = [12 x i8] c"foo_symlink\00"
@.str.5 = [8 x i8] c"trouble\00"
@.str.6 = [15 x i8] c"retval was %d\0A\00"
define i32 @main() {
%1 = alloca <4 x i32>
%2 = load i32, i32* @O_RDONLY
%3 = load i32, i32* @O_DIRECTORY
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @O_RDONLY
%7 = load i32, i32* @O_DIRECTORY
%8 = or i32 %7, %6
%9 = tail call i32 (i32, i8*, i32, ...) @openat(i32 %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%12 = load i32, i32* @O_WRONLY
%13 = load i32, i32* @O_CREAT
%14 = or i32 %13, %12
%15 = load i32, i32* @O_EXCL
%16 = or i32 %14, %15
%17 = tail call i32 (i32, i8*, i32, ...) @openat(i32 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %16, i32 438)
%18 = bitcast <4 x i32>* %1 to i8*
%19 = bitcast <4 x i32>* %1 to %struct.timespec*
%20 = load i32, i32* @UTIME_NOW
%21 = insertelement <4 x i32> poison, i32 %20, i64 0
%22 = shufflevector <4 x i32> %21, <4 x i32> poison, <4 x i32> zeroinitializer
store <4 x i32> %22, <4 x i32>* %1
%23 = call i32 @utimensat(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), %struct.timespec* %19, i32 0)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %0
%26 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %27
27: ; preds = %25, %0
%28 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %23)
ret i32 0
}