#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 atoi(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *getcwd(char *, int);
char *getenv(char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
char *realpath(char *, int /*<<< orphan*/ *);
int starts_with(char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ useage();
int main(int argc, char **argv) {
  int c, width = -1;
  char pathbuf[1024];
  char *home, *realhome, *path;
  int next = 0;
  char *lastpth = NULL;
  while ((c = getopt(argc, argv, "hw:")) != -1) {
    switch (c) {
    case 'w':
      width = atoi(optarg);
      break;
    case 'h':
      useage();
      exit(0);
      break;
    }
  }
  if (getcwd(pathbuf, 1024 * sizeof(char)) == NULL) {
    perror("Error getting current working directory");
    return 1;
  }
  home = getenv("HOME");
  realhome = realpath(home, NULL);
  if (realhome != NULL) {
    home = realhome;
  } else {
    perror("Faild resolving home path");
    exit(1);
  }
  int homelen = strlen(home);
  int in_home = starts_with(home, pathbuf, homelen);
  if (in_home)
    path = pathbuf + homelen;
  else
    path = pathbuf;
  if (in_home) {
    putchar('~');
  }
  while (*path != '\0') {
    if (next) {
      putchar(*path);
      next = 0;
    }
    if (*path == '/') {
      putchar(*path);
      next = 1;
      lastpth = path + 2;
    }
    path++;
  }
  if (lastpth != NULL)
    puts(lastpth);
  else
    putchar('\n');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x0,-0x43c(%rbp)
movq   $0x0,-0x448(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdfd(%rip),%rdx
call   10b0 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1268 <main+0xa8>
mov    -0x14(%rbp),%eax
mov    %eax,-0x454(%rbp)
sub    $0x68,%eax
je     1255 <main+0x95>
jmp    122b <main+0x6b>
mov    -0x454(%rbp),%eax
sub    $0x77,%eax
jne    1263 <main+0xa3>
jmp    123f <main+0x7f>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   10c0 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    1263 <main+0xa3>
mov    $0x0,%al
call   10e0 <useage@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
jmp    11f5 <main+0x35>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1070 <getcwd@plt>
cmp    $0x0,%rax
jne    129b <main+0xdb>
lea    0xd7a(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    143f <main+0x27f>
lea    0xd8a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <realpath@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
je     12e6 <main+0x126>
mov    -0x430(%rbp),%rax
mov    %rax,-0x428(%rbp)
jmp    12fc <main+0x13c>
lea    0xd44(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x428(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x44c(%rbp)
mov    -0x428(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    -0x44c(%rbp),%edx
call   1090 <starts_with@plt>
mov    %eax,-0x450(%rbp)
cmpl   $0x0,-0x450(%rbp)
je     1357 <main+0x197>
lea    -0x420(%rbp),%rax
movslq -0x44c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x438(%rbp)
jmp    1365 <main+0x1a5>
lea    -0x420(%rbp),%rax
mov    %rax,-0x438(%rbp)
cmpl   $0x0,-0x450(%rbp)
je     137c <main+0x1bc>
mov    $0x7e,%edi
call   1040 <putchar@plt>
jmp    1381 <main+0x1c1>
mov    -0x438(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     140f <main+0x24f>
cmpl   $0x0,-0x43c(%rbp)
je     13ba <main+0x1fa>
mov    -0x438(%rbp),%rax
movsbl (%rax),%edi
call   1040 <putchar@plt>
movl   $0x0,-0x43c(%rbp)
mov    -0x438(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    13f8 <main+0x238>
mov    -0x438(%rbp),%rax
movsbl (%rax),%edi
call   1040 <putchar@plt>
movl   $0x1,-0x43c(%rbp)
mov    -0x438(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x448(%rbp)
mov    -0x438(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x438(%rbp)
jmp    1381 <main+0x1c1>
cmpq   $0x0,-0x448(%rbp)
je     142e <main+0x26e>
mov    -0x448(%rbp),%rdi
call   1050 <puts@plt>
jmp    1438 <main+0x278>
mov    $0xa,%edi
call   1040 <putchar@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe27(%rip),%r14
mov    0x2e18(%rip),%r15
jmp    11f8 <main+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15),%edi
call   10c0 <atoi@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10b0 <getopt@plt>
cmp    $0x77,%eax
je     11f0 <main+0x30>
cmp    $0xffffffff,%eax
je     1222 <main+0x62>
cmp    $0x68,%eax
jne    11f8 <main+0x38>
xor    %eax,%eax
call   10e0 <useage@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
call   1070 <getcwd@plt>
test   %rax,%rax
je     130f <main+0x14f>
lea    0xdea(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1080 <realpath@plt>
test   %rax,%rax
je     1322 <main+0x162>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1090 <starts_with@plt>
xor    %ebp,%ebp
movslq %ebx,%rcx
lea    (%rsp,%rcx,1),%rbx
test   %eax,%eax
cmovne %rcx,%rbp
cmove  %r14,%rbx
je     1293 <main+0xd3>
mov    $0x7e,%edi
call   1040 <putchar@plt>
mov    (%rsp,%rbp,1),%al
test   %al,%al
je     12f5 <main+0x135>
add    $0x2,%rbx
xor    %ebp,%ebp
xor    %ecx,%ecx
jmp    12bc <main+0xfc>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl -0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     12e6 <main+0x126>
test   %ecx,%ecx
je     12cc <main+0x10c>
movsbl %al,%edi
call   1040 <putchar@plt>
movzbl -0x2(%rbx),%eax
xor    %ecx,%ecx
cmp    $0x2f,%al
jne    12b0 <main+0xf0>
mov    $0x2f,%edi
call   1040 <putchar@plt>
mov    $0x1,%ecx
mov    %rbx,%rbp
jmp    12b0 <main+0xf0>
test   %rbp,%rbp
je     12f5 <main+0x135>
mov    %rbp,%rdi
call   1050 <puts@plt>
jmp    12ff <main+0x13f>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcee(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%eax
jmp    1301 <main+0x141>
lea    0xd08(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"hw:\00"
@optarg = global i32 0
@.str.1 = [40 x i8] c"Error getting current working directory\00"
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [26 x i8] c"Faild resolving home path\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %7
store i32 0, i32* %12
store i8* null, i8** %13
br label %16
16: ; preds = %29, %2
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt(i32 %17, i8** %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %19, i32* %6
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %30
21: ; preds = %16
%22 = load i32, i32* %6
switch i32 %22, label %29 [
i32 119, label %23
i32 104, label %26
]
23: ; preds = %21
%24 = load i32, i32* @optarg
%25 = call i32 @atoi(i32 %24)
store i32 %25, i32* %7
br label %29
26: ; preds = %21
%27 = call i32 (...) @useage()
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %21, %23
br label %16
30: ; preds = %16
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%32 = call i32* @getcwd(i8* %31, i32 1024)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %104
36: ; preds = %30
%37 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %37, i8** %9
%38 = load i8*, i8** %9
%39 = call i8* @realpath(i8* %38, i32* null)
store i8* %39, i8** %10
%40 = load i8*, i8** %10
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = load i8*, i8** %10
store i8* %43, i8** %9
br label %47
44: ; preds = %36
%45 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %42
%48 = load i8*, i8** %9
%49 = call i32 @strlen(i8* %48)
store i32 %49, i32* %14
%50 = load i8*, i8** %9
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%52 = load i32, i32* %14
%53 = call i32 @starts_with(i8* %50, i8* %51, i32 %52)
store i32 %53, i32* %15
%54 = load i32, i32* %15
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %47
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%58 = load i32, i32* %14
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
store i8* %60, i8** %11
br label %63
61: ; preds = %47
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
store i8* %62, i8** %11
br label %63
63: ; preds = %61, %56
%64 = load i32, i32* %15
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = call i32 @putchar(i8 signext 126)
br label %68
68: ; preds = %66, %63
br label %69
69: ; preds = %92, %68
%70 = load i8*, i8** %11
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %95
74: ; preds = %69
%75 = load i32, i32* %12
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %81
77: ; preds = %74
%78 = load i8*, i8** %11
%79 = load i8, i8* %78
%80 = call i32 @putchar(i8 signext %79)
store i32 0, i32* %12
br label %81
81: ; preds = %77, %74
%82 = load i8*, i8** %11
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = icmp eq i32 %84, 47
br i1 %85, label %86, label %92
86: ; preds = %81
%87 = load i8*, i8** %11
%88 = load i8, i8* %87
%89 = call i32 @putchar(i8 signext %88)
store i32 1, i32* %12
%90 = load i8*, i8** %11
%91 = getelementptr inbounds i8, i8* %90, i64 2
store i8* %91, i8** %13
br label %92
92: ; preds = %86, %81
%93 = load i8*, i8** %11
%94 = getelementptr inbounds i8, i8* %93, i32 1
store i8* %94, i8** %11
br label %69
95: ; preds = %69
%96 = load i8*, i8** %13
%97 = icmp ne i8* %96, null
br i1 %97, label %98, label %101
98: ; preds = %95
%99 = load i8*, i8** %13
%100 = call i32 @puts(i8* %99)
br label %103
101: ; preds = %95
%102 = call i32 @putchar(i8 signext 10)
br label %103
103: ; preds = %101, %98
store i32 0, i32* %3
br label %104
104: ; preds = %103, %34
%105 = load i32, i32* %3
ret i32 %105
}

LLVM IR (-O2):
@.str = [4 x i8] c"hw:\00"
@optarg = global i32 0
@.str.1 = [40 x i8] c"Error getting current working directory\00"
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [26 x i8] c"Faild resolving home path\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %7, %2
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %6, label %7 [
i32 -1, label %14
i32 119, label %8
i32 104, label %11
]
7: ; preds = %5, %8
br label %5
8: ; preds = %5
%9 = load i32, i32* @optarg
%10 = tail call i32 @atoi(i32 %9)
br label %7
11: ; preds = %5
%12 = tail call i32 (...) @useage()
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %5
%15 = call i32* @getcwd(i8* %4, i32 1024)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %65
19: ; preds = %14
%20 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%21 = call i8* @realpath(i8* %20, i32* null)
%22 = icmp eq i8* %21, null
br i1 %22, label %30, label %23
23: ; preds = %19
%24 = call i32 @strlen(i8* %21)
%25 = call i32 @starts_with(i8* %21, i8* %4, i32 %24)
%26 = icmp eq i32 %25, 0
%27 = sext i32 %24 to i64
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %27
%29 = select i1 %26, i8* %4, i8* %28
br i1 %26, label %35, label %33
30: ; preds = %19
%31 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %23
%34 = call i32 @putchar(i8 signext 126)
br label %35
35: ; preds = %33, %23
%36 = load i8, i8* %29
%37 = icmp eq i8 %36, 0
br i1 %37, label %63, label %38
38: ; preds = %35, %53
%39 = phi i8 [ %57, %53 ], [ %36, %35 ]
%40 = phi i8* [ %55, %53 ], [ null, %35 ]
%41 = phi i32 [ %54, %53 ], [ 0, %35 ]
%42 = phi i8* [ %56, %53 ], [ %29, %35 ]
%43 = icmp eq i32 %41, 0
br i1 %43, label %47, label %44
44: ; preds = %38
%45 = call i32 @putchar(i8 signext %39)
%46 = load i8, i8* %42
br label %47
47: ; preds = %44, %38
%48 = phi i8 [ %46, %44 ], [ %39, %38 ]
%49 = icmp eq i8 %48, 47
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = call i32 @putchar(i8 signext 47)
%52 = getelementptr inbounds i8, i8* %42, i64 2
br label %53
53: ; preds = %50, %47
%54 = phi i32 [ 1, %50 ], [ 0, %47 ]
%55 = phi i8* [ %52, %50 ], [ %40, %47 ]
%56 = getelementptr inbounds i8, i8* %42, i64 1
%57 = load i8, i8* %56
%58 = icmp eq i8 %57, 0
br i1 %58, label %59, label %38
59: ; preds = %53
%60 = icmp eq i8* %55, null
br i1 %60, label %63, label %61
61: ; preds = %59
%62 = call i32 @puts(i8* %55)
br label %65
63: ; preds = %35, %59
%64 = call i32 @putchar(i8 signext 10)
br label %65
65: ; preds = %61, %63, %17
%66 = phi i32 [ 1, %17 ], [ 0, %63 ], [ 0, %61 ]
ret i32 %66
}