#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 option {
  char *member_0;
  int member_3;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_1;
};

/* Variables and functions */
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ errx(int, char *, char *);
char *getcwd(int /*<<< orphan*/ *, int /*<<< orphan*/);
char *getenv(char *);
int getopt_long(int, char **, char *, struct option *, int /*<<< orphan*/ *);
int help(char *, char *);
scalar_t__ isAbsolutePath(char const *);
int /*<<< orphan*/ no_argument;
int optind;
int /*<<< orphan*/ puts(char const *);
int version(char *);
int main(int argc, char *argv[]) {
  struct option longopts[] = {{"help", no_argument, 0, 0},
                              {"version", no_argument, 0, 1},
                              {0, 0, 0, 0}};
  bool logical = true;
  int c;
  while ((c = getopt_long(argc, argv, "LP", longopts, NULL)) != -1) {
    switch (c) {
    case 0:
      return help(argv[0], "[OPTIONS]\n"
                           "  -L                       print logical path\n"
                           "  -P                       print physical path\n"
                           "      --help               display this help\n"
                           "      --version            display version info");
    case 1:
      return version(argv[0]);
    case 'L':
      logical = true;
      break;
    case 'P':
      logical = false;
      break;
    case '?':
      return 1;
    }
  }
  if (optind < argc) {
    errx(1, "extra operand '%s'", argv[optind]);
  }
  const char *pwd = getenv("PWD");
  if (logical && pwd && isAbsolutePath(pwd)) {
    puts(pwd);
  } else {
    pwd = getcwd(NULL, 0);
    if (!pwd)
      err(1, "getcwd");
    puts(pwd);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe3c(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x50(%rbp)
add    $0x18,%rdi
lea    0xe18(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x1,-0x38(%rbp)
add    $0x18,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
movl   $0x1,-0x64(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x60(%rbp),%rcx
lea    0xdd9(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1050 <getopt_long@plt>
mov    %eax,-0x68(%rbp)
cmp    $0xffffffff,%eax
je     12f9 <main+0x159>
mov    -0x68(%rbp),%eax
mov    %eax,-0x74(%rbp)
test   %eax,%eax
je     12a1 <main+0x101>
jmp    125d <main+0xbd>
mov    -0x74(%rbp),%eax
sub    $0x1,%eax
je     12bc <main+0x11c>
jmp    126e <main+0xce>
mov    -0x74(%rbp),%eax
sub    $0x3f,%eax
je     12e8 <main+0x148>
jmp    127f <main+0xdf>
mov    -0x74(%rbp),%eax
sub    $0x4c,%eax
je     12d0 <main+0x130>
jmp    1290 <main+0xf0>
mov    -0x74(%rbp),%eax
sub    $0x50,%eax
je     12dc <main+0x13c>
jmp    12f4 <main+0x154>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd61(%rip),%rsi
call   10c0 <help@plt>
mov    %eax,-0x4(%rbp)
jmp    13a8 <main+0x208>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <version@plt>
mov    %eax,-0x4(%rbp)
jmp    13a8 <main+0x208>
movl   $0x1,-0x64(%rbp)
jmp    12f4 <main+0x154>
movl   $0x0,-0x64(%rbp)
jmp    12f4 <main+0x154>
movl   $0x1,-0x4(%rbp)
jmp    13a8 <main+0x208>
jmp    1222 <main+0x82>
mov    0x2ce8(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    132e <main+0x18e>
mov    -0x10(%rbp),%rax
mov    0x2cd2(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdx
mov    $0x1,%edi
lea    0xdab(%rip),%rsi
call   1060 <errx@plt>
lea    0xdb2(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x70(%rbp)
cmpl   $0x0,-0x64(%rbp)
je     1374 <main+0x1d4>
cmpq   $0x0,-0x70(%rbp)
je     1374 <main+0x1d4>
mov    -0x70(%rbp),%rdi
call   1090 <isAbsolutePath@plt>
cmp    $0x0,%rax
je     1374 <main+0x1d4>
mov    -0x70(%rbp),%rdi
call   1040 <puts@plt>
jmp    13a8 <main+0x208>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1080 <getcwd@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    139f <main+0x1ff>
mov    $0x1,%edi
lea    0xd51(%rip),%rsi
call   10b0 <err@plt>
mov    -0x70(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe58(%rip),%rax
mov    %rax,(%rsp)
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
movq   $0x0,0xc(%rsp)
lea    0xe3c(%rip),%rcx
mov    %rcx,0x18(%rsp)
mov    %eax,0x20(%rsp)
movabs $0x100000000,%rax
mov    %rax,0x24(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movq   $0x0,0x40(%rsp)
mov    $0x1,%r12d
lea    0xe0e(%rip),%r14
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %r8d,%r8d
call   1050 <getopt_long@plt>
cmp    $0x3e,%eax
jg     1240 <main+0xb0>
cmp    $0xffffffff,%eax
je     1260 <main+0xd0>
test   %eax,%eax
je     12b5 <main+0x125>
cmp    $0x1,%eax
jne    1210 <main+0x80>
jmp    12c8 <main+0x138>
nop
cmp    $0x3f,%eax
je     12d4 <main+0x144>
cmp    $0x4c,%eax
je     1258 <main+0xc8>
cmp    $0x50,%eax
jne    1210 <main+0x80>
xor    %r12d,%r12d
jmp    1210 <main+0x80>
mov    $0x1,%r12d
jmp    1210 <main+0x80>
mov    0x2d81(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    1283 <main+0xf3>
mov    (%rbx,%rax,8),%rdx
lea    0xe5b(%rip),%rsi
mov    $0x1,%edi
call   1060 <errx@plt>
lea    0xe5d(%rip),%rdi
call   1030 <getenv@plt>
test   %r12d,%r12d
je     12db <main+0x14b>
mov    %rax,%rbx
test   %rax,%rax
je     12db <main+0x14b>
mov    %rbx,%rdi
call   1080 <isAbsolutePath@plt>
test   %rax,%rax
je     12db <main+0x14b>
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    1307 <main+0x177>
mov    (%rbx),%rdi
lea    0xd51(%rip),%rsi
call   10b0 <help@plt>
mov    %eax,%ebx
jmp    1307 <main+0x177>
mov    (%rbx),%rdi
call   1090 <version@plt>
mov    %eax,%ebx
jmp    1307 <main+0x177>
mov    $0x1,%ebx
jmp    1307 <main+0x177>
xor    %ebx,%ebx
xor    %edi,%edi
xor    %esi,%esi
call   1070 <getcwd@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    12ff <main+0x16f>
lea    0xdf6(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.option = type { i8*, i32, i32, i32 }
@.str = [5 x i8] c"help\00"
@no_argument = global i32 0
@.str.1 = [8 x i8] c"version\00"
@.str.2 = [3 x i8] c"LP\00"
@.str.3 = [196 x i8] c"[OPTIONS]\0A -L print logical path\0A -P print physical path\0A --help display this help\0A --version display version info\00"
@optind = global i32 0
@.str.4 = [19 x i8] c"extra operand '%s'\00"
@.str.5 = [4 x i8] c"PWD\00"
@.str.6 = [7 x i8] c"getcwd\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [3 x %struct.option]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %6, i64 0, i64 0
%11 = getelementptr inbounds %struct.option, %struct.option* %10, i32 0, i32 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds %struct.option, %struct.option* %10, i32 0, i32 1
%13 = load i32, i32* @no_argument
store i32 %13, i32* %12
%14 = getelementptr inbounds %struct.option, %struct.option* %10, i32 0, i32 2
store i32 0, i32* %14
%15 = getelementptr inbounds %struct.option, %struct.option* %10, i32 0, i32 3
store i32 0, i32* %15
%16 = getelementptr inbounds %struct.option, %struct.option* %10, i64 1
%17 = getelementptr inbounds %struct.option, %struct.option* %16, i32 0, i32 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds %struct.option, %struct.option* %16, i32 0, i32 1
%19 = load i32, i32* @no_argument
store i32 %19, i32* %18
%20 = getelementptr inbounds %struct.option, %struct.option* %16, i32 0, i32 2
store i32 0, i32* %20
%21 = getelementptr inbounds %struct.option, %struct.option* %16, i32 0, i32 3
store i32 1, i32* %21
%22 = getelementptr inbounds %struct.option, %struct.option* %16, i64 1
%23 = bitcast %struct.option* %22 to i8*
store i32 1, i32* %7
br label %24
24: ; preds = %45, %2
%25 = load i32, i32* %4
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %6, i64 0, i64 0
%28 = call i32 @getopt_long(i32 %25, i8** %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.option* %27, i32* null)
store i32 %28, i32* %8
%29 = icmp ne i32 %28, -1
br i1 %29, label %30, label %46
30: ; preds = %24
%31 = load i32, i32* %8
switch i32 %31, label %45 [
i32 0, label %32
i32 1, label %37
i32 76, label %42
i32 80, label %43
i32 63, label %44
]
32: ; preds = %30
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @help(i8* %35, i8* getelementptr inbounds ([196 x i8], [196 x i8]* @.str.3, i64 0, i64 0))
store i32 %36, i32* %3
br label %80
37: ; preds = %30
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 0
%40 = load i8*, i8** %39
%41 = call i32 @version(i8* %40)
store i32 %41, i32* %3
br label %80
42: ; preds = %30
store i32 1, i32* %7
br label %45
43: ; preds = %30
store i32 0, i32* %7
br label %45
44: ; preds = %30
store i32 1, i32* %3
br label %80
45: ; preds = %30, %43, %42
br label %24
46: ; preds = %24
%47 = load i32, i32* @optind
%48 = load i32, i32* %4
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %57
50: ; preds = %46
%51 = load i8**, i8*** %5
%52 = load i32, i32* @optind
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 @errx(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %50, %46
%58 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store i8* %58, i8** %9
%59 = load i32, i32* %7
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %71
61: ; preds = %57
%62 = load i8*, i8** %9
%63 = icmp ne i8* %62, null
br i1 %63, label %64, label %71
64: ; preds = %61
%65 = load i8*, i8** %9
%66 = call i64 @isAbsolutePath(i8* %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %64
%69 = load i8*, i8** %9
%70 = call i32 @puts(i8* %69)
br label %80
71: ; preds = %64, %61, %57
%72 = call i8* @getcwd(i32* null, i32 0)
store i8* %72, i8** %9
%73 = load i8*, i8** %9
%74 = icmp ne i8* %73, null
br i1 %74, label %77, label %75
75: ; preds = %71
%76 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %77
77: ; preds = %75, %71
%78 = load i8*, i8** %9
%79 = call i32 @puts(i8* %78)
br label %80
80: ; preds = %32, %37, %44, %77, %68
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
%struct.option = type { i8*, i32, i32, i32 }
@.str = [5 x i8] c"help\00"
@no_argument = global i32 0
@.str.1 = [8 x i8] c"version\00"
@.str.2 = [3 x i8] c"LP\00"
@.str.3 = [196 x i8] c"[OPTIONS]\0A -L print logical path\0A -P print physical path\0A --help display this help\0A --version display version info\00"
@optind = global i32 0
@.str.4 = [19 x i8] c"extra operand '%s'\00"
@.str.5 = [4 x i8] c"PWD\00"
@.str.6 = [7 x i8] c"getcwd\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [3 x %struct.option]
%4 = bitcast [3 x %struct.option]* %3 to i8*
%5 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 0
%6 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 0, i32 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 0, i32 1
%8 = load i32, i32* @no_argument
store i32 %8, i32* %7
%9 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 0, i32 2
store i32 0, i32* %9
%10 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 0, i32 3
store i32 0, i32* %10
%11 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 1, i32 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 1, i32 1
store i32 %8, i32* %12
%13 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 1, i32 2
store i32 0, i32* %13
%14 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 1, i32 3
store i32 1, i32* %14
%15 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 2
%16 = bitcast %struct.option* %15 to i8*
br label %17
17: ; preds = %28, %2
%18 = phi i32 [ 1, %2 ], [ %29, %28 ]
br label %19
19: ; preds = %17, %19
%20 = call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.option* %5, i32* null)
switch i32 %20, label %19 [
i32 -1, label %30
i32 0, label %21
i32 1, label %24
i32 76, label %28
i32 80, label %27
i32 63, label %55
]
21: ; preds = %19
%22 = load i8*, i8** %1
%23 = call i32 @help(i8* %22, i8* getelementptr inbounds ([196 x i8], [196 x i8]* @.str.3, i64 0, i64 0))
br label %55
24: ; preds = %19
%25 = load i8*, i8** %1
%26 = call i32 @version(i8* %25)
br label %55
27: ; preds = %19
br label %28
28: ; preds = %19, %27
%29 = phi i32 [ 0, %27 ], [ 1, %19 ]
br label %17
30: ; preds = %19
%31 = load i32, i32* @optind
%32 = icmp slt i32 %31, %0
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = sext i32 %31 to i64
%35 = getelementptr inbounds i8*, i8** %1, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 @errx(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %33, %30
%39 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%40 = icmp ne i32 %18, 0
%41 = icmp ne i8* %39, null
%42 = and i1 %40, %41
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = call i64 @isAbsolutePath(i8* %39)
%45 = icmp eq i64 %44, 0
br i1 %45, label %48, label %46
46: ; preds = %43
%47 = call i32 @puts(i8* %39)
br label %55
48: ; preds = %43, %38
%49 = call i8* @getcwd(i32* null, i32 0)
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %53
53: ; preds = %51, %48
%54 = call i32 @puts(i8* dereferenceable(1) %49)
br label %55
55: ; preds = %19, %46, %53, %24, %21
%56 = phi i32 [ %26, %24 ], [ %23, %21 ], [ 0, %53 ], [ 0, %46 ], [ 1, %19 ]
ret i32 %56
}