#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
char *realpath(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char *path, *resolved_path, *returned_path;
  if (argc < 2 || argc > 3) {
    fprintf(stderr, "Usage: %s path [resolved_path]\n", argv[0]);
    exit(2);
  }
  path = argv[1];
  resolved_path = argc > 2 ? argv[2] : NULL;
  if ((returned_path = realpath(path, resolved_path)) == NULL) {
    perror("realpath");
    exit(1);
  }
  printf("%s\n", returned_path);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     117a <main+0x2a>
cmpl   $0x3,-0x8(%rbp)
jle    11a0 <main+0x50>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe6f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11c7 <main+0x77>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    11d2 <main+0x82>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11d2 <main+0x82>
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <realpath@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    120b <main+0xbb>
lea    0xe24(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rsi
lea    0xe13(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %edi,%eax
lea    -0x4(%rax),%ecx
cmp    $0xfffffffd,%ecx
jbe    1189 <main+0x39>
mov    0x8(%rsi),%rdi
cmp    $0x3,%eax
jb     116a <main+0x1a>
mov    0x10(%rsi),%rsi
jmp    116c <main+0x1c>
xor    %esi,%esi
call   1050 <realpath@plt>
test   %rax,%rax
je     11ab <main+0x5b>
lea    0xeac(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe64(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
lea    0xe6e(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Usage: %s path [resolved_path]\0A\00"
@.str.1 = [9 x i8] c"realpath\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 3
br i1 %13, label %14, label %21
14: ; preds = %11, %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 2)
unreachable
21: ; preds = %11
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %6
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 2
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
br label %32
31: ; preds = %21
br label %32
32: ; preds = %31, %27
%33 = phi i8* [ %30, %27 ], [ null, %31 ]
store i8* %33, i8** %7
%34 = load i8*, i8** %6
%35 = load i8*, i8** %7
%36 = call i8* @realpath(i8* %34, i8* %35)
store i8* %36, i8** %8
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %32
%42 = load i8*, i8** %8
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %42)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Usage: %s path [resolved_path]\0A\00"
@.str.1 = [9 x i8] c"realpath\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add i32 %0, -4
%4 = icmp ult i32 %3, -2
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 2)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = icmp ugt i32 %0, 2
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
br label %17
17: ; preds = %10, %14
%18 = phi i8* [ %16, %14 ], [ null, %10 ]
%19 = tail call i8* @realpath(i8* %12, i8* %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %17
%25 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %19)
ret i32 0
}