#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 /*<<< orphan*/ AT_SYMLINK_NOFOLLOW;
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}};
  utimensat(subd, "foo_symlink_typo", ts, AT_SYMLINK_NOFOLLOW);
  char *mynull = ((char *)5) - 5;
  utimensat(subd, mynull, ts, AT_SYMLINK_NOFOLLOW);
  utimensat(subd, "", ts, AT_SYMLINK_NOFOLLOW);
  int retval = utimensat(subd, "foo_symlink", ts, AT_SYMLINK_NOFOLLOW);
  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    0x2dc8(%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
mov    0x2d73(%rip),%rax
mov    (%rax),%ecx
lea    0xdd9(%rip),%rsi
call   1030 <utimensat@plt>
mov    $0x5,%eax
add    $0xfffffffffffffffb,%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%rsi
lea    -0x20(%rbp),%rdx
mov    0x2d46(%rip),%rax
mov    (%rax),%ecx
call   1030 <utimensat@plt>
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rdx
mov    0x2d31(%rip),%rax
mov    (%rax),%ecx
lea    0xdca(%rip),%rsi
call   1030 <utimensat@plt>
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rdx
mov    0x2d15(%rip),%rax
mov    (%rax),%ecx
lea    0xd8c(%rip),%rsi
call   1030 <utimensat@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    12c2 <main+0x162>
lea    0xd7f(%rip),%rdi
call   1080 <perror@plt>
mov    -0x2c(%rbp),%esi
lea    0xd78(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e68(%rip),%r14
mov    0x2e51(%rip),%rbx
mov    (%rbx),%esi
or     (%r14),%esi
lea    0xe7d(%rip),%rdi
call   1070 <open@plt>
mov    (%rbx),%edx
or     (%r14),%edx
lea    0xe70(%rip),%rsi
mov    %eax,%edi
xor    %eax,%eax
call   1040 <openat@plt>
mov    %eax,%ebx
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
mov    %ebx,%edx
call   1060 <fprintf@plt>
mov    0x2de3(%rip),%rax
mov    0x2e34(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2de9(%rip),%rax
or     (%rax),%edx
lea    0xe40(%rip),%rsi
mov    %ebx,%edi
mov    $0x1b6,%ecx
xor    %eax,%eax
call   1040 <openat@plt>
mov    0x2e03(%rip),%rax
movd   (%rax),%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa %xmm0,(%rsp)
mov    0x2dae(%rip),%r15
mov    (%r15),%ecx
lea    0xe13(%rip),%rsi
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <utimensat@plt>
mov    (%r15),%ecx
mov    %ebx,%edi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <utimensat@plt>
mov    (%r15),%ecx
lea    0xe20(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <utimensat@plt>
mov    (%r15),%ecx
lea    0xdea(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <utimensat@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1270 <main+0x110>
lea    0xde7(%rip),%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdc5(%rip),%rdi
call   1080 <perror@plt>
jmp    1256 <main+0xf6>

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 = [17 x i8] c"foo_symlink_typo\00"
@AT_SYMLINK_NOFOLLOW = global i32 0
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [12 x i8] c"foo_symlink\00"
@.str.7 = [8 x i8] c"trouble\00"
@.str.8 = [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 i8*
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @O_RDONLY
%8 = load i32, i32* @O_DIRECTORY
%9 = or i32 %7, %8
%10 = call i32 @open(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = load i32, i32* @O_RDONLY
%13 = load i32, i32* @O_DIRECTORY
%14 = or i32 %12, %13
%15 = call i32 (i32, i8*, i32, ...) @openat(i32 %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 %15, i32* %3
%16 = load i32, i32* @stderr
%17 = load i32, i32* %3
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %3
%20 = load i32, i32* @O_WRONLY
%21 = load i32, i32* @O_CREAT
%22 = or i32 %20, %21
%23 = load i32, i32* @O_EXCL
%24 = or i32 %22, %23
%25 = call i32 (i32, i8*, i32, ...) @openat(i32 %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 438)
%26 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 0
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %26, i32 0, i32 0
%28 = load i32, i32* @UTIME_NOW
store i32 %28, i32* %27
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %26, i32 0, i32 1
%30 = load i32, i32* @UTIME_NOW
store i32 %30, i32* %29
%31 = getelementptr inbounds %struct.timespec, %struct.timespec* %26, i64 1
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %31, i32 0, i32 0
%33 = load i32, i32* @UTIME_NOW
store i32 %33, i32* %32
%34 = getelementptr inbounds %struct.timespec, %struct.timespec* %31, i32 0, i32 1
%35 = load i32, i32* @UTIME_NOW
store i32 %35, i32* %34
%36 = load i32, i32* %3
%37 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 0
%38 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%39 = call i32 @utimensat(i32 %36, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), %struct.timespec* %37, i32 %38)
store i8* getelementptr inbounds (i8, i8* inttoptr (i64 5 to i8*), i64 -5), i8** %5
%40 = load i32, i32* %3
%41 = load i8*, i8** %5
%42 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 0
%43 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%44 = call i32 @utimensat(i32 %40, i8* %41, %struct.timespec* %42, i32 %43)
%45 = load i32, i32* %3
%46 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 0
%47 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%48 = call i32 @utimensat(i32 %45, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), %struct.timespec* %46, i32 %47)
%49 = load i32, i32* %3
%50 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 0
%51 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%52 = call i32 @utimensat(i32 %49, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), %struct.timespec* %50, i32 %51)
store i32 %52, i32* %6
%53 = load i32, i32* %6
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %0
%56 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %57
57: ; preds = %55, %0
%58 = load i32, i32* %6
%59 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %58)
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 = [17 x i8] c"foo_symlink_typo\00"
@AT_SYMLINK_NOFOLLOW = global i32 0
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [12 x i8] c"foo_symlink\00"
@.str.7 = [8 x i8] c"trouble\00"
@.str.8 = [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 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%24 = call i32 @utimensat(i32 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), %struct.timespec* %19, i32 %23)
%25 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%26 = call i32 @utimensat(i32 %9, i8* null, %struct.timespec* %19, i32 %25)
%27 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%28 = call i32 @utimensat(i32 %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), %struct.timespec* %19, i32 %27)
%29 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%30 = call i32 @utimensat(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), %struct.timespec* %19, i32 %29)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %0
%33 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %34
34: ; preds = %32, %0
%35 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %30)
ret i32 0
}