#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int PATH_MAX;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
char *realpath(char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char *symlinkpath = NULL;
  char actualpath[PATH_MAX];
  char *ptr;
  if (argc > 1) {
    symlinkpath = argv[1];
    if ((ptr = realpath(symlinkpath, actualpath))) {
      printf("%s\n", ptr);
      return EXIT_SUCCESS;
    }
    fprintf(stderr, "realpath: %s when reading '%s'\n", strerror(errno),
            symlinkpath);
  } else
    fprintf(stderr, "realpath: missing file name\n");
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    121a <main+0xda>
mov    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <realpath@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11e3 <main+0xa3>
mov    -0x30(%rbp),%rsi
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1244 <main+0x104>
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
mov    -0x18(%rbp),%rcx
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1231 <main+0xf1>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    0x2ea2(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rax
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rax
mov    %rax,%rsp
cmp    $0x2,%edi
jl     1192 <main+0x52>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <realpath@plt>
test   %rax,%rax
je     11ab <main+0x6b>
lea    0xe7f(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    0x2e30(%rip),%rax
jmp    11e1 <main+0xa1>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11da <main+0x9a>
mov    0x2e26(%rip),%rax
mov    (%rax),%r14d
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe3a(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"realpath: %s when reading '%s'\0A\00"
@errno = global i32 0
@.str.2 = [29 x i8] c"realpath: missing file name\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%11 = load i32, i32* @PATH_MAX
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i8, i64 %12
store i64 %12, i64* %8
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %34
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = call i8* @realpath(i8* %21, i8* %14)
store i8* %22, i8** %9
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i8*, i8** %9
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_SUCCESS
store i32 %27, i32* %3
store i32 1, i32* %10
br label %39
28: ; preds = %17
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = load i8*, i8** %6
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %31, i8* %32)
br label %37
34: ; preds = %2
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %34, %28
%38 = load i32, i32* @EXIT_FAILURE
store i32 %38, i32* %3
store i32 1, i32* %10
br label %39
39: ; preds = %37, %24
%40 = load i8*, i8** %7
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"realpath: %s when reading '%s'\0A\00"
@errno = global i32 0
@.str.2 = [29 x i8] c"realpath: missing file name\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %19
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = call i8* @realpath(i8* %9, i8* %5)
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %22
14: ; preds = %7
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %9)
br label %22
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %14, %19, %12
%23 = phi i32* [ @EXIT_SUCCESS, %12 ], [ @EXIT_FAILURE, %19 ], [ @EXIT_FAILURE, %14 ]
%24 = load i32, i32* %23
ret i32 %24
}