#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*/ free(char *);
char *get_full_path(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int test2() {
  int l, i;
  char *full_path = NULL;
  char *p[20];
  i = 0;
  p[i++] = "~/hoge/fuga/piyo.txt";
  p[i++] = "./test/test.txt";
  p[i++] = "/test/test/./../test.txt";
  p[i++] = "test/../test.txt";
  p[i++] = "../../../../../../test.txt";
  p[i++] = "./////test.txt";
  p[i++] = "~/test////test.txt";
  p[i++] = "~/hoge/../fuga/../piyo/../.././/test.txt";
  p[i++] = "./hoge/../fuga/../piyo/../.././/test.txt";
  p[i++] = "./hoge/~/fuga/.~/piyo/../.././/test.txt";
  l = i;
  for (i = 0; i < l; i++) {
    full_path = get_full_path(p[i]);
    printf("%s -> %s\n", p[i], full_path);
    free(full_path);
  }
  return 0;
}


x86 assembly (clang, -O0):
<test2>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
lea    0xea2(%rip),%rcx
mov    %rcx,-0xb0(%rbp,%rax,8)
ff
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
lea    0xe9b(%rip),%rcx
mov    %rcx,-0xb0(%rbp,%rax,8)
ff
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
lea    0xe8f(%rip),%rcx
mov    %rcx,-0xb0(%rbp,%rax,8)
ff
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
lea    0xe8c(%rip),%rcx
mov    %rcx,-0xb0(%rbp,%rax,8)
ff
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
lea    0xe81(%rip),%rcx
mov    %rcx,-0xb0(%rbp,%rax,8)
ff
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
lea    0xe80(%rip),%rcx
mov    %rcx,-0xb0(%rbp,%rax,8)
ff
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
lea    0xe73(%rip),%rcx
mov    %rcx,-0xb0(%rbp,%rax,8)
ff
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
lea    0xe6a(%rip),%rcx
mov    %rcx,-0xb0(%rbp,%rax,8)
ff
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
lea    0xe77(%rip),%rcx
mov    %rcx,-0xb0(%rbp,%rax,8)
ff
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
lea    0xe84(%rip),%rcx
mov    %rcx,-0xb0(%rbp,%rax,8)
ff
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12c3 <test2+0x193>
movslq -0x8(%rbp),%rax
mov    -0xb0(%rbp,%rax,8),%rdi
ff
call   1050 <get_full_path@plt>
mov    %rax,-0x10(%rbp)
movslq -0x8(%rbp),%rax
mov    -0xb0(%rbp,%rax,8),%rsi
ff
mov    -0x10(%rbp),%rdx
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    126f <test2+0x13f>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test2>:
push   %r15
push   %r14
push   %rbx
lea    0xec4(%rip),%r15
mov    %r15,%rdi
call   1050 <get_full_path@plt>
mov    %rax,%rbx
lea    0xfb8(%rip),%r14
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xeaa(%rip),%r15
mov    %r15,%rdi
call   1050 <get_full_path@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe92(%rip),%r15
mov    %r15,%rdi
call   1050 <get_full_path@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe83(%rip),%r15
mov    %r15,%rdi
call   1050 <get_full_path@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe6c(%rip),%r15
mov    %r15,%rdi
call   1050 <get_full_path@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe5f(%rip),%r15
mov    %r15,%rdi
call   1050 <get_full_path@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe46(%rip),%r15
mov    %r15,%rdi
call   1050 <get_full_path@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe31(%rip),%r15
mov    %r15,%rdi
call   1050 <get_full_path@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe32(%rip),%r15
mov    %r15,%rdi
call   1050 <get_full_path@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe33(%rip),%r15
mov    %r15,%rdi
call   1050 <get_full_path@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"~/hoge/fuga/piyo.txt\00"
@.str.1 = [16 x i8] c"./test/test.txt\00"
@.str.2 = [25 x i8] c"/test/test/./../test.txt\00"
@.str.3 = [17 x i8] c"test/../test.txt\00"
@.str.4 = [27 x i8] c"../../../../../../test.txt\00"
@.str.5 = [15 x i8] c"./////test.txt\00"
@.str.6 = [19 x i8] c"~/test////test.txt\00"
@.str.7 = [41 x i8] c"~/hoge/../fuga/../piyo/../.././/test.txt\00"
@.str.8 = [41 x i8] c"./hoge/../fuga/../piyo/../.././/test.txt\00"
@.str.9 = [40 x i8] c"./hoge/~/fuga/.~/piyo/../.././/test.txt\00"
@.str.10 = [10 x i8] c"%s -> %s\0A\00"
define i32 @test2() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [20 x i8*]
store i8* null, i8** %3
store i32 0, i32* %2
%5 = load i32, i32* %2
%6 = add nsw i32 %5, 1
store i32 %6, i32* %2
%7 = sext i32 %5 to i64
%8 = getelementptr inbounds [20 x i8*], [20 x i8*]* %4, i64 0, i64 %7
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8** %8
%9 = load i32, i32* %2
%10 = add nsw i32 %9, 1
store i32 %10, i32* %2
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds [20 x i8*], [20 x i8*]* %4, i64 0, i64 %11
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %12
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
store i32 %14, i32* %2
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds [20 x i8*], [20 x i8*]* %4, i64 0, i64 %15
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8** %16
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
store i32 %18, i32* %2
%19 = sext i32 %17 to i64
%20 = getelementptr inbounds [20 x i8*], [20 x i8*]* %4, i64 0, i64 %19
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8** %20
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds [20 x i8*], [20 x i8*]* %4, i64 0, i64 %23
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8** %24
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds [20 x i8*], [20 x i8*]* %4, i64 0, i64 %27
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8** %28
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 1
store i32 %30, i32* %2
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds [20 x i8*], [20 x i8*]* %4, i64 0, i64 %31
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8** %32
%33 = load i32, i32* %2
%34 = add nsw i32 %33, 1
store i32 %34, i32* %2
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds [20 x i8*], [20 x i8*]* %4, i64 0, i64 %35
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i8** %36
%37 = load i32, i32* %2
%38 = add nsw i32 %37, 1
store i32 %38, i32* %2
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds [20 x i8*], [20 x i8*]* %4, i64 0, i64 %39
store i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), i8** %40
%41 = load i32, i32* %2
%42 = add nsw i32 %41, 1
store i32 %42, i32* %2
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds [20 x i8*], [20 x i8*]* %4, i64 0, i64 %43
store i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0), i8** %44
%45 = load i32, i32* %2
store i32 %45, i32* %1
store i32 0, i32* %2
br label %46
46: ; preds = %64, %0
%47 = load i32, i32* %2
%48 = load i32, i32* %1
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %67
50: ; preds = %46
%51 = load i32, i32* %2
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [20 x i8*], [20 x i8*]* %4, i64 0, i64 %52
%54 = load i8*, i8** %53
%55 = call i8* @get_full_path(i8* %54)
store i8* %55, i8** %3
%56 = load i32, i32* %2
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [20 x i8*], [20 x i8*]* %4, i64 0, i64 %57
%59 = load i8*, i8** %58
%60 = load i8*, i8** %3
%61 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %59, i8* %60)
%62 = load i8*, i8** %3
%63 = call i32 @free(i8* %62)
br label %64
64: ; preds = %50
%65 = load i32, i32* %2
%66 = add nsw i32 %65, 1
store i32 %66, i32* %2
br label %46
67: ; preds = %46
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"~/hoge/fuga/piyo.txt\00"
@.str.1 = [16 x i8] c"./test/test.txt\00"
@.str.2 = [25 x i8] c"/test/test/./../test.txt\00"
@.str.3 = [17 x i8] c"test/../test.txt\00"
@.str.4 = [27 x i8] c"../../../../../../test.txt\00"
@.str.5 = [15 x i8] c"./////test.txt\00"
@.str.6 = [19 x i8] c"~/test////test.txt\00"
@.str.7 = [41 x i8] c"~/hoge/../fuga/../piyo/../.././/test.txt\00"
@.str.8 = [41 x i8] c"./hoge/../fuga/../piyo/../.././/test.txt\00"
@.str.9 = [40 x i8] c"./hoge/~/fuga/.~/piyo/../.././/test.txt\00"
@.str.10 = [10 x i8] c"%s -> %s\0A\00"
define i32 @test2() {
%1 = tail call i8* @get_full_path(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %1)
%3 = tail call i32 @free(i8* %1)
%4 = tail call i8* @get_full_path(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%6 = tail call i32 @free(i8* %4)
%7 = tail call i8* @get_full_path(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%9 = tail call i32 @free(i8* %7)
%10 = tail call i8* @get_full_path(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%12 = tail call i32 @free(i8* %10)
%13 = tail call i8* @get_full_path(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%14 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%15 = tail call i32 @free(i8* %13)
%16 = tail call i8* @get_full_path(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%17 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %16)
%18 = tail call i32 @free(i8* %16)
%19 = tail call i8* @get_full_path(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%20 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %19)
%21 = tail call i32 @free(i8* %19)
%22 = tail call i8* @get_full_path(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0))
%23 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i8* %22)
%24 = tail call i32 @free(i8* %22)
%25 = tail call i8* @get_full_path(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0))
%26 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), i8* %25)
%27 = tail call i32 @free(i8* %25)
%28 = tail call i8* @get_full_path(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0))
%29 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0), i8* %28)
%30 = tail call i32 @free(i8* %28)
ret i32 0
}