#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 */
typedef int /*<<< orphan*/ cwd;

/* Variables and functions */
int MAXPATHLEN;
int /*<<< orphan*/ check_rc(char *, int, char *, int);
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ rel2abs_file_ok(char *, char *, char *, char *);
int /*<<< orphan*/ rel2abs_ok(char *, char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void test_003(void) {
  char cwd[MAXPATHLEN];
  if (!getcwd(cwd, sizeof(cwd)))
    check_rc(
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/AndyA/rfile/refs/heads/master/t/filename.c",
        97, "-1", -1);
  {
    char want[MAXPATHLEN];
    strcpy(want, cwd);
    strcat(want, "/foo");
    rel2abs_ok("bar/../foo", NULL, want, "abs relative to cwd");
    rel2abs_ok("../foo", "bar", want, "abs relative to relative");
  }
  rel2abs_ok("/", NULL, "/", "abs unchanged 1");
  rel2abs_ok("/", "../foo", "/", "abs unchanged 2");
  rel2abs_ok("../../bin", "/usr/local/bin", "/usr/bin", "up and down");
  rel2abs_file_ok("../local/bin/perl", "/usr/bin/perl", "/usr/local/bin/perl",
                  "from file 1");
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x8(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x10(%rbp)
mov    %eax,%esi
call   1050 <getcwd@plt>
cmp    $0x0,%eax
jne    11c1 <test_003+0x61>
lea    0xe55(%rip),%rdi
mov    $0x61,%esi
lea    0xece(%rip),%rdx
mov    $0xffffffff,%ecx
call   1080 <check_rc@plt>
mov    -0x28(%rbp),%rsi
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rdx
lea    0xe77(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    0xe77(%rip),%rcx
call   1040 <rel2abs_ok@plt>
mov    -0x30(%rbp),%rdx
lea    0xe60(%rip),%rdi
lea    0xe74(%rip),%rsi
lea    0xe71(%rip),%rcx
call   1040 <rel2abs_ok@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
lea    0xe77(%rip),%rdx
xor    %eax,%eax
mov    %eax,%esi
lea    0xe6e(%rip),%rcx
mov    %rdx,%rdi
call   1040 <rel2abs_ok@plt>
lea    0xe5d(%rip),%rdx
lea    0xe1e(%rip),%rsi
lea    0xe61(%rip),%rcx
mov    %rdx,%rdi
call   1040 <rel2abs_ok@plt>
lea    0xe62(%rip),%rdi
lea    0xe65(%rip),%rsi
lea    0xe6d(%rip),%rdx
lea    0xe6f(%rip),%rcx
call   1040 <rel2abs_ok@plt>
lea    0xe6f(%rip),%rdi
lea    0xe7a(%rip),%rsi
lea    0xe81(%rip),%rdx
lea    0xe8e(%rip),%rcx
call   1060 <rel2abs_file_ok@plt>
mov    -0x8(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e77(%rip),%rbx
mov    (%rbx),%esi
mov    %rsp,%r14
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
call   1050 <getcwd@plt>
test   %eax,%eax
jne    11b0 <test_003+0x50>
lea    0xe66(%rip),%rdi
lea    0xee4(%rip),%rdx
mov    $0x61,%esi
mov    $0xffffffff,%ecx
call   1080 <check_rc@plt>
mov    %rsp,%r15
mov    (%rbx),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xeb6(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
lea    0xea1(%rip),%rdi
lea    0xea5(%rip),%rcx
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <rel2abs_ok@plt>
lea    0xe8d(%rip),%r14
lea    0xea1(%rip),%rsi
lea    0xe9e(%rip),%rcx
mov    %r14,%rdi
mov    %rbx,%rdx
call   1040 <rel2abs_ok@plt>
mov    %r15,%rsp
lea    0xea2(%rip),%rbx
lea    0xe9d(%rip),%rcx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <rel2abs_ok@plt>
lea    0xe99(%rip),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <rel2abs_ok@plt>
lea    0xe94(%rip),%rdi
lea    0xe97(%rip),%rsi
lea    0xe9f(%rip),%rdx
lea    0xea1(%rip),%rcx
call   1040 <rel2abs_ok@plt>
lea    0xea1(%rip),%rdi
lea    0xeac(%rip),%rsi
lea    0xeb3(%rip),%rdx
lea    0xec0(%rip),%rcx
call   1060 <rel2abs_file_ok@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@.str = [133 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AndyA/rfile/refs/heads/master/t/filename.c\00"
@.str.1 = [3 x i8] c"-1\00"
@.str.2 = [5 x i8] c"/foo\00"
@.str.3 = [11 x i8] c"bar/../foo\00"
@.str.4 = [20 x i8] c"abs relative to cwd\00"
@.str.5 = [7 x i8] c"../foo\00"
@.str.6 = [4 x i8] c"bar\00"
@.str.7 = [25 x i8] c"abs relative to relative\00"
@.str.8 = [2 x i8] c"/\00"
@.str.9 = [16 x i8] c"abs unchanged 1\00"
@.str.10 = [16 x i8] c"abs unchanged 2\00"
@.str.11 = [10 x i8] c"../../bin\00"
@.str.12 = [15 x i8] c"/usr/local/bin\00"
@.str.13 = [9 x i8] c"/usr/bin\00"
@.str.14 = [12 x i8] c"up and down\00"
@.str.15 = [18 x i8] c"../local/bin/perl\00"
@.str.16 = [14 x i8] c"/usr/bin/perl\00"
@.str.17 = [20 x i8] c"/usr/local/bin/perl\00"
@.str.18 = [12 x i8] c"from file 1\00"
define void @test_003() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = load i32, i32* @MAXPATHLEN
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
store i8* %7, i8** %1
%8 = alloca i8, i64 %6
store i64 %6, i64* %2
%9 = trunc i64 %6 to i32
%10 = call i32 @getcwd(i8* %8, i32 %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %0
%13 = call i32 @check_rc(i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str, i64 0, i64 0), i32 97, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 -1)
br label %14
14: ; preds = %12, %0
%15 = load i32, i32* @MAXPATHLEN
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %3
%18 = alloca i8, i64 %16
store i64 %16, i64* %4
%19 = call i32 @strcpy(i8* %18, i8* %8)
%20 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @rel2abs_ok(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* null, i8* %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @rel2abs_ok(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
%23 = load i8*, i8** %3
%24 = call i32 @rel2abs_ok(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%25 = call i32 @rel2abs_ok(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
%26 = call i32 @rel2abs_ok(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0))
%27 = call i32 @rel2abs_file_ok(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.17, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.18, i64 0, i64 0))
%28 = load i8*, i8** %1
ret void
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@.str = [133 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AndyA/rfile/refs/heads/master/t/filename.c\00"
@.str.1 = [3 x i8] c"-1\00"
@.str.2 = [5 x i8] c"/foo\00"
@.str.3 = [11 x i8] c"bar/../foo\00"
@.str.4 = [20 x i8] c"abs relative to cwd\00"
@.str.5 = [7 x i8] c"../foo\00"
@.str.6 = [4 x i8] c"bar\00"
@.str.7 = [25 x i8] c"abs relative to relative\00"
@.str.8 = [2 x i8] c"/\00"
@.str.9 = [16 x i8] c"abs unchanged 1\00"
@.str.10 = [16 x i8] c"abs unchanged 2\00"
@.str.11 = [10 x i8] c"../../bin\00"
@.str.12 = [15 x i8] c"/usr/local/bin\00"
@.str.13 = [9 x i8] c"/usr/bin\00"
@.str.14 = [12 x i8] c"up and down\00"
@.str.15 = [18 x i8] c"../local/bin/perl\00"
@.str.16 = [14 x i8] c"/usr/bin/perl\00"
@.str.17 = [20 x i8] c"/usr/local/bin/perl\00"
@.str.18 = [12 x i8] c"from file 1\00"
define void @test_003() {
%1 = load i32, i32* @MAXPATHLEN
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = call i32 @getcwd(i8* %3, i32 %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @check_rc(i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str, i64 0, i64 0), i32 97, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 -1)
br label %8
8: ; preds = %6, %0
%9 = load i32, i32* @MAXPATHLEN
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = call i32 @strcpy(i8* %12, i8* %3)
%14 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @rel2abs_ok(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* null, i8* %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @rel2abs_ok(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
%17 = call i32 @rel2abs_ok(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%18 = call i32 @rel2abs_ok(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
%19 = call i32 @rel2abs_ok(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0))
%20 = call i32 @rel2abs_file_ok(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.17, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.18, i64 0, i64 0))
ret void
}