#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 */

/* Variables and functions */
int AT_FDCWD;
int /*<<< orphan*/ O_RDONLY;
int open(char *, int /*<<< orphan*/);
int openat(int, char *, int /*<<< orphan*/);
int main(void) {
  int dfd = open("/tmp", O_RDONLY);
  __attribute__((unused)) int fd1 = openat(dfd, "abc", O_RDONLY);
  __attribute__((unused)) int fd2 = openat(0x12345678, "/tmp/abc", O_RDONLY);
  __attribute__((unused)) int fd3 = openat(AT_FDCWD, "abc", O_RDONLY);
  __attribute__((unused)) int fd4 = openat(0x12345678, "abc", O_RDONLY);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%esi
lea    0xec1(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e97(%rip),%rax
mov    (%rax),%edx
lea    0xeb0(%rip),%rsi
call   1030 <openat@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
mov    $0x12345678,%edi
lea    0xe8e(%rip),%rsi
call   1030 <openat@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
lea    0xe72(%rip),%rsi
call   1030 <openat@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
mov    $0x12345678,%edi
lea    0xe55(%rip),%rsi
call   1030 <openat@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2ebd(%rip),%rbx
mov    (%rbx),%esi
lea    0xecc(%rip),%rdi
call   1040 <open@plt>
mov    (%rbx),%edx
lea    0xec8(%rip),%r14
mov    %eax,%edi
mov    %r14,%rsi
call   1030 <openat@plt>
mov    (%rbx),%edx
lea    0xeb0(%rip),%rsi
mov    $0x12345678,%edi
call   1030 <openat@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%edx
mov    %r14,%rsi
call   1030 <openat@plt>
mov    (%rbx),%edx
mov    $0x12345678,%edi
mov    %r14,%rsi
call   1030 <openat@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"/tmp\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"abc\00"
@.str.2 = [9 x i8] c"/tmp/abc\00"
@AT_FDCWD = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @openat(i32 %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @openat(i32 305419896, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* @AT_FDCWD
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @openat(i32 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15)
store i32 %16, i32* %5
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @openat(i32 305419896, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %17)
store i32 %18, i32* %6
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"/tmp\00"
@O_RDONLY = global i32 0
@.str.1 = [4 x i8] c"abc\00"
@.str.2 = [9 x i8] c"/tmp/abc\00"
@AT_FDCWD = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @openat(i32 %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @openat(i32 305419896, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @AT_FDCWD
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @openat(i32 %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @openat(i32 305419896, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %10)
ret i32 0
}