#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int PATH_MAX;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ readlink(char *, char *, int);
int main(void) {
  char buffer[2 * PATH_MAX];
  if (!getcwd(buffer, sizeof(buffer))) {
    perror("getcwd");
    exit(EXIT_FAILURE);
  }
  if (readlink("/bin/abs-true", buffer, sizeof(buffer)) < 0) {
    perror("readlink");
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
mov    %rax,-0x28(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x20(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    %eax,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%eax
jne    11ab <main+0x6b>
lea    0xe68(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    %eax,%edx
lea    0xe4b(%rip),%rdi
call   1030 <readlink@plt>
cmp    $0x0,%rax
jge    11e5 <main+0xa5>
lea    0xe43(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    0x2ea2(%rip),%rax
mov    (%rax),%r14d
add    %r14d,%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <getcwd@plt>
test   %eax,%eax
jne    117d <main+0x3d>
lea    0xe85(%rip),%rdi
jmp    119b <main+0x5b>
lea    0xe83(%rip),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <readlink@plt>
test   %rax,%rax
jns    11ae <main+0x6e>
lea    0xe7a(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [7 x i8] c"getcwd\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"/bin/abs-true\00"
@.str.2 = [9 x i8] c"readlink\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
store i32 0, i32* %1
%4 = load i32, i32* @PATH_MAX
%5 = mul nsw i32 2, %4
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
store i8* %7, i8** %2
%8 = alloca i8, i64 %6
store i64 %6, i64* %3
%9 = trunc i64 %6 to i32
%10 = call i32 @getcwd(i8* %8, i32 %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %0
%17 = trunc i64 %6 to i32
%18 = call i64 @readlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %16
%25 = load i32, i32* @EXIT_SUCCESS
%26 = call i32 @exit(i32 %25)
unreachable
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [7 x i8] c"getcwd\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"/bin/abs-true\00"
@.str.2 = [9 x i8] c"readlink\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @PATH_MAX
%2 = shl nsw i32 %1, 1
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @getcwd(i8* %4, i32 %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = call i64 @readlink(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32 %2)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %11
%19 = load i32, i32* @EXIT_SUCCESS
%20 = call i32 @exit(i32 %19)
unreachable
}