#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AT_FDCWD;
int O_DIRECTORY;
int O_RDONLY;
int futimesat(int, char *, struct timeval *);
int openat(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int subd = openat(AT_FDCWD, "tmp/subdir1", O_RDONLY | O_DIRECTORY);
  struct timeval *ts = NULL;
  futimesat(subd, "foo_symlink_typo", ts);
  char *mynull = ((char *)5) - 5;
  futimesat(subd, mynull, ts);
  futimesat(subd, "", ts);
  int retval = futimesat(subd, "foo_symlink", ts);
  if (retval < 0) {
    perror("trouble");
  }
  printf("retval was %d\n", retval);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    0x2e89(%rip),%rax
mov    (%rax),%edx
mov    0x2e70(%rip),%rax
or     (%rax),%edx
lea    0xe8f(%rip),%rsi
call   1030 <openat@plt>
mov    %eax,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7d(%rip),%rsi
call   1060 <futimesat@plt>
mov    $0x5,%eax
add    $0xfffffffffffffffb,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <futimesat@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rdx
lea    0xe80(%rip),%rsi
call   1060 <futimesat@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rdx
lea    0xe4b(%rip),%rsi
call   1060 <futimesat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11f0 <main+0xb0>
lea    0xe3e(%rip),%rdi
call   1050 <perror@plt>
mov    -0x1c(%rbp),%esi
lea    0xe37(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
mov    0x2e97(%rip),%rax
mov    0x2e80(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe9d(%rip),%rsi
call   1030 <openat@plt>
mov    %eax,%ebx
lea    0xe9b(%rip),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1060 <futimesat@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <futimesat@plt>
lea    0xeb3(%rip),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1060 <futimesat@plt>
lea    0xe81(%rip),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1060 <futimesat@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11bd <main+0x7d>
lea    0xe7f(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe65(%rip),%rdi
call   1050 <perror@plt>
jmp    11ab <main+0x6b>

LLVM IR (-O0):
%struct.timeval = type { i32 }
@AT_FDCWD = global i32 0
@.str = [12 x i8] c"tmp/subdir1\00"
@O_RDONLY = global i32 0
@O_DIRECTORY = global i32 0
@.str.1 = [17 x i8] c"foo_symlink_typo\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [12 x i8] c"foo_symlink\00"
@.str.4 = [8 x i8] c"trouble\00"
@.str.5 = [15 x i8] c"retval was %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.timeval*
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @AT_FDCWD
%7 = load i32, i32* @O_RDONLY
%8 = load i32, i32* @O_DIRECTORY
%9 = or i32 %7, %8
%10 = call i32 @openat(i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %2
store %struct.timeval* null, %struct.timeval** %3
%11 = load i32, i32* %2
%12 = load %struct.timeval*, %struct.timeval** %3
%13 = call i32 @futimesat(i32 %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), %struct.timeval* %12)
store i8* getelementptr inbounds (i8, i8* inttoptr (i64 5 to i8*), i64 -5), i8** %4
%14 = load i32, i32* %2
%15 = load i8*, i8** %4
%16 = load %struct.timeval*, %struct.timeval** %3
%17 = call i32 @futimesat(i32 %14, i8* %15, %struct.timeval* %16)
%18 = load i32, i32* %2
%19 = load %struct.timeval*, %struct.timeval** %3
%20 = call i32 @futimesat(i32 %18, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %struct.timeval* %19)
%21 = load i32, i32* %2
%22 = load %struct.timeval*, %struct.timeval** %3
%23 = call i32 @futimesat(i32 %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), %struct.timeval* %22)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %0
%27 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %26, %0
%29 = load i32, i32* %5
%30 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %29)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@AT_FDCWD = global i32 0
@.str = [12 x i8] c"tmp/subdir1\00"
@O_RDONLY = global i32 0
@O_DIRECTORY = global i32 0
@.str.1 = [17 x i8] c"foo_symlink_typo\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [12 x i8] c"foo_symlink\00"
@.str.4 = [8 x i8] c"trouble\00"
@.str.5 = [15 x i8] c"retval was %d\0A\00"
define i32 @main() {
%1 = load i32, i32* @AT_FDCWD
%2 = load i32, i32* @O_RDONLY
%3 = load i32, i32* @O_DIRECTORY
%4 = or i32 %3, %2
%5 = tail call i32 @openat(i32 %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i32 @futimesat(i32 %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), %struct.timeval* null)
%7 = tail call i32 @futimesat(i32 %5, i8* null, %struct.timeval* null)
%8 = tail call i32 @futimesat(i32 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %struct.timeval* null)
%9 = tail call i32 @futimesat(i32 %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), %struct.timeval* null)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %9)
ret i32 0
}