#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*/ PATH_MAX;
char *dupcat(char *, char *, char *, int /*<<< orphan*/ *);
char *dupstr(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
char *get_pwd();
char *malloc(int /*<<< orphan*/);
char *path_translate(char *);
char *realpath(char *, char *);
int /*<<< orphan*/ stderr;
char *do_path_translate(char *arg, int verbose) {
  char *dir, *path, *path2;
  if (verbose) {
    fprintf(stderr, "doit: need to translate path \"%s\"\n", arg);
  }
  path2 = malloc(PATH_MAX);
  path = realpath(arg, path2);
  if (!path) {
    if (arg[0] == '/') {
      path = dupstr(arg);
    } else {
      dir = get_pwd();
      path = dupcat(dir, "/", arg, NULL);
      free(dir);
    }
  }
  if (verbose) {
    fprintf(stderr, "doit: canonification gives \"%s\"\n", path);
  }
  path2 = path_translate(path);
  free(path);
  if (verbose) {
    fprintf(stderr, "doit: path translation gives \"%s\"\n", path2);
  }
  return path2;
}


x86 assembly (clang, -O0):
<do_path_translate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11b2 <do_path_translate+0x32>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe53(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <realpath@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1237 <do_path_translate+0xb7>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1202 <do_path_translate+0x82>
mov    -0x8(%rbp),%rdi
call   10a0 <dupstr@plt>
mov    %rax,-0x20(%rbp)
jmp    1232 <do_path_translate+0xb2>
mov    $0x0,%al
call   1040 <get_pwd@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe07(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <dupcat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    1237 <do_path_translate+0xb7>
cmpl   $0x0,-0xc(%rbp)
je     125a <do_path_translate+0xda>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdd0(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <path_translate@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0xc(%rbp)
je     1293 <do_path_translate+0x113>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xdb8(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_path_translate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
test   %esi,%esi
je     11a9 <do_path_translate+0x29>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1090 <malloc@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1080 <realpath@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11da <do_path_translate+0x5a>
cmpb   $0x2f,(%rbx)
jne    1235 <do_path_translate+0xb5>
mov    %rbx,%rdi
call   10a0 <dupstr@plt>
mov    %rax,%rbp
test   %r14d,%r14d
je     11f7 <do_path_translate+0x77>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
mov    %rbp,%rdx
call   1060 <fprintf@plt>
mov    %rbp,%rdi
call   1070 <path_translate@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <free@plt>
test   %r14d,%r14d
je     1227 <do_path_translate+0xa7>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1040 <get_pwd@plt>
mov    %rax,%r15
lea    0xddd(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1050 <dupcat@plt>
mov    %rax,%rbp
mov    %r15,%rdi
call   1030 <free@plt>
test   %r14d,%r14d
jne    11df <do_path_translate+0x5f>
jmp    11f7 <do_path_translate+0x77>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"doit: need to translate path \22%s\22\0A\00"
@PATH_MAX = global i32 0
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [33 x i8] c"doit: canonification gives \22%s\22\0A\00"
@.str.3 = [35 x i8] c"doit: path translation gives \22%s\22\0A\00"
define i8* @do_path_translate(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %3
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %10, %2
%15 = load i32, i32* @PATH_MAX
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %7
%17 = load i8*, i8** %3
%18 = load i8*, i8** %7
%19 = call i8* @realpath(i8* %17, i8* %18)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %39, label %22
22: ; preds = %14
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 47
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i8*, i8** %3
%30 = call i8* @dupstr(i8* %29)
store i8* %30, i8** %6
br label %38
31: ; preds = %22
%32 = call i8* (...) @get_pwd()
store i8* %32, i8** %5
%33 = load i8*, i8** %5
%34 = load i8*, i8** %3
%35 = call i8* @dupcat(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %34, i32* null)
store i8* %35, i8** %6
%36 = load i8*, i8** %5
%37 = call i32 @free(i8* %36)
br label %38
38: ; preds = %31, %28
br label %39
39: ; preds = %38, %14
%40 = load i32, i32* %4
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %6
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %42, %39
%47 = load i8*, i8** %6
%48 = call i8* @path_translate(i8* %47)
store i8* %48, i8** %7
%49 = load i8*, i8** %6
%50 = call i32 @free(i8* %49)
%51 = load i32, i32* %4
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %46
%54 = load i32, i32* @stderr
%55 = load i8*, i8** %7
%56 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %53, %46
%58 = load i8*, i8** %7
ret i8* %58
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"doit: need to translate path \22%s\22\0A\00"
@PATH_MAX = global i32 0
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [33 x i8] c"doit: canonification gives \22%s\22\0A\00"
@.str.3 = [35 x i8] c"doit: path translation gives \22%s\22\0A\00"
define i8* @do_path_translate(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %7
7: ; preds = %4, %2
%8 = load i32, i32* @PATH_MAX
%9 = tail call i8* @malloc(i32 %8)
%10 = tail call i8* @realpath(i8* %0, i8* %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %21
12: ; preds = %7
%13 = load i8, i8* %0
%14 = icmp eq i8 %13, 47
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i8* @dupstr(i8* %0)
br label %21
17: ; preds = %12
%18 = tail call i8* (...) @get_pwd()
%19 = tail call i8* @dupcat(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32* null)
%20 = tail call i32 @free(i8* %18)
br label %21
21: ; preds = %15, %17, %7
%22 = phi i8* [ %10, %7 ], [ %16, %15 ], [ %19, %17 ]
br i1 %3, label %26, label %23
23: ; preds = %21
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %26
26: ; preds = %23, %21
%27 = tail call i8* @path_translate(i8* %22)
%28 = tail call i32 @free(i8* %22)
br i1 %3, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %27)
br label %32
32: ; preds = %29, %26
ret i8* %27
}