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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ logError(char *, int, int, ...);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ snprintf(char *, int const, char *, char *, ...);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
char *strrchr(char const *, char);
char *getAbsolutePath(const char *filename, char *szAbsPath,
                      const int pathSize) {
  char *p;
  int nPathLen;
  char szPath[1024];
  char cwd[256];
  p = strrchr(filename, '/');
  if (p == NULL) {
    szPath[0] = '\0';
  } else {
    nPathLen = p - filename;
    if (nPathLen >= sizeof(szPath)) {
      logError("file: "
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/"
               "master/fastdfs-5.01/common/shared_func.c"
               ", line: %d, "
               "filename length: %d is too long, exceeds %d",
               118, nPathLen, (int)sizeof(szPath));
      return NULL;
    }
    memcpy(szPath, filename, nPathLen);
    szPath[nPathLen] = '\0';
  }
  if (szPath[0] == '/') {
    snprintf(szAbsPath, pathSize, "%s", szPath);
  } else {
    if (getcwd(cwd, sizeof(cwd)) == NULL) {
      logError("file: "
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/"
               "master/fastdfs-5.01/common/shared_func.c"
               ", line: %d, "
               "call getcwd fail, errno: %d, error info: %s",
               136, errno,
               (strerror(errno) != NULL ? strerror(errno) : "Unkown error"));
      return NULL;
    }
    nPathLen = strlen(cwd);
    if (cwd[nPathLen - 1] == '/') {
      cwd[nPathLen - 1] = '\0';
    }
    if (szPath[0] != '\0') {
      snprintf(szAbsPath, pathSize, "%s/%s", cwd, szPath);
    } else {
      snprintf(szAbsPath, pathSize, "%s", cwd);
    }
  }
  return szAbsPath;
}


x86 assembly (clang, -O0):
<getAbsolutePath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x540,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11af <getAbsolutePath+0x3f>
movb   $0x0,-0x430(%rbp)
jmp    1214 <getAbsolutePath+0xa4>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    $0x400,%rax
jb     11f5 <getAbsolutePath+0x85>
mov    -0x2c(%rbp),%edx
lea    0xe29(%rip),%rdi
mov    $0x76,%esi
mov    $0x400,%ecx
mov    $0x0,%al
call   1060 <logError@plt>
movq   $0x0,-0x8(%rbp)
jmp    137a <getAbsolutePath+0x20a>
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1080 <memcpy@plt>
movslq -0x2c(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
movsbl -0x430(%rbp),%eax
cmp    $0x2f,%eax
jne    1245 <getAbsolutePath+0xd5>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x430(%rbp),%rcx
lea    0xf7c(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    1372 <getAbsolutePath+0x202>
lea    -0x530(%rbp),%rdi
mov    $0x100,%esi
call   1070 <getcwd@plt>
cmp    $0x0,%rax
jne    12e1 <getAbsolutePath+0x171>
mov    0x2d79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x534(%rbp)
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
cmp    $0x0,%rax
je     12a1 <getAbsolutePath+0x131>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %rax,-0x540(%rbp)
jmp    12b4 <getAbsolutePath+0x144>
lea    0xf10(%rip),%rax
mov    %rax,-0x540(%rbp)
jmp    12b4 <getAbsolutePath+0x144>
mov    -0x534(%rbp),%edx
mov    -0x540(%rbp),%rcx
lea    0xe14(%rip),%rdi
mov    $0x88,%esi
mov    $0x0,%al
call   1060 <logError@plt>
movq   $0x0,-0x8(%rbp)
jmp    137a <getAbsolutePath+0x20a>
lea    -0x530(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x530(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    1319 <getAbsolutePath+0x1a9>
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x530(%rbp,%rax,1)
movsbl -0x430(%rbp),%eax
cmp    $0x0,%eax
je     1351 <getAbsolutePath+0x1e1>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x530(%rbp),%rcx
lea    -0x430(%rbp),%r8
lea    0xe80(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    136d <getAbsolutePath+0x1fd>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x530(%rbp),%rcx
lea    0xe4f(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    1372 <getAbsolutePath+0x202>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x540,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAbsolutePath>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x508,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11c0 <getAbsolutePath+0x50>
sub    %rbp,%rax
test   $0xfffffc00,%eax
je     11ca <getAbsolutePath+0x5a>
lea    0xe5a(%rip),%rdi
xor    %ebx,%ebx
mov    $0x76,%esi
mov    %eax,%edx
mov    $0x400,%ecx
xor    %eax,%eax
call   1060 <logError@plt>
jmp    12b4 <getAbsolutePath+0x144>
movb   $0x0,0x100(%rsp)
jmp    1206 <getAbsolutePath+0x96>
mov    %eax,%r15d
lea    0x100(%rsp),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1080 <memcpy@plt>
movb   $0x0,0x100(%rsp,%r15,1)
cmpb   $0x2f,0x100(%rsp)
2f
jne    1206 <getAbsolutePath+0x96>
lea    0xfbc(%rip),%rdx
lea    0x100(%rsp),%rcx
jmp    1287 <getAbsolutePath+0x117>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
call   1070 <getcwd@plt>
test   %rax,%rax
je     125c <getAbsolutePath+0xec>
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbp,1)
jne    1231 <getAbsolutePath+0xc1>
movb   $0x0,-0x1(%rsp,%rax,1)
cmpb   $0x0,0x100(%rsp)
je     127d <getAbsolutePath+0x10d>
lea    0xf83(%rip),%rdx
mov    %rsp,%rcx
lea    0x100(%rsp),%r8
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    12b4 <getAbsolutePath+0x144>
mov    0x2d7d(%rip),%rbx
mov    (%rbx),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
test   %rax,%rax
je     1296 <getAbsolutePath+0x126>
mov    (%rbx),%edi
call   1090 <strerror@plt>
mov    %rax,%rcx
jmp    129d <getAbsolutePath+0x12d>
lea    0xf31(%rip),%rdx
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    12b4 <getAbsolutePath+0x144>
lea    0xf1b(%rip),%rcx
lea    0xe38(%rip),%rdi
xor    %ebx,%ebx
mov    $0x88,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <logError@plt>
mov    %rbx,%rax
add    $0x508,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [220 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/shared_func.c, line: %d, filename length: %d is too long, exceeds %d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [220 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/shared_func.c, line: %d, call getcwd fail, errno: %d, error info: %s\00"
@errno = global i32 0
@.str.3 = [13 x i8] c"Unkown error\00"
@.str.4 = [6 x i8] c"%s/%s\00"
define i8* @getAbsolutePath(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca [256 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = load i8*, i8** %5
%13 = call i8* @strrchr(i8* %12, i8 signext 47)
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
store i8 0, i8* %17
br label %39
18: ; preds = %3
%19 = load i8*, i8** %8
%20 = load i8*, i8** %5
%21 = ptrtoint i8* %19 to i64
%22 = ptrtoint i8* %20 to i64
%23 = sub i64 %21, %22
%24 = trunc i64 %23 to i32
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = icmp uge i64 %26, 1024
br i1 %27, label %28, label %31
28: ; preds = %18
%29 = load i32, i32* %9
%30 = call i32 (i8*, i32, i32, ...) @logError(i8* getelementptr inbounds ([220 x i8], [220 x i8]* @.str, i64 0, i64 0), i32 118, i32 %29, i32 1024)
store i8* null, i8** %4
br label %99
31: ; preds = %18
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%33 = load i8*, i8** %5
%34 = load i32, i32* %9
%35 = call i32 @memcpy(i8* %32, i8* %33, i32 %34)
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %37
store i8 0, i8* %38
br label %39
39: ; preds = %31, %16
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 47
br i1 %43, label %44, label %49
44: ; preds = %39
%45 = load i8*, i8** %6
%46 = load i32, i32* %7
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%48 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %45, i32 %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %47)
br label %97
49: ; preds = %39
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%51 = call i32* @getcwd(i8* %50, i32 256)
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %65
53: ; preds = %49
%54 = load i32, i32* @errno
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
br label %62
61: ; preds = %53
br label %62
62: ; preds = %61, %58
%63 = phi i8* [ %60, %58 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), %61 ]
%64 = call i32 (i8*, i32, i32, ...) @logError(i8* getelementptr inbounds ([220 x i8], [220 x i8]* @.str.2, i64 0, i64 0), i32 136, i32 %54, i8* %63)
store i8* null, i8** %4
br label %99
65: ; preds = %49
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%67 = call i32 @strlen(i8* %66)
store i32 %67, i32* %9
%68 = load i32, i32* %9
%69 = sub nsw i32 %68, 1
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 %70
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 47
br i1 %74, label %75, label %80
75: ; preds = %65
%76 = load i32, i32* %9
%77 = sub nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 %78
store i8 0, i8* %79
br label %80
80: ; preds = %75, %65
%81 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %91
85: ; preds = %80
%86 = load i8*, i8** %6
%87 = load i32, i32* %7
%88 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%89 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%90 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %86, i32 %87, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %88, i8* %89)
br label %96
91: ; preds = %80
%92 = load i8*, i8** %6
%93 = load i32, i32* %7
%94 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%95 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %92, i32 %93, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %94)
br label %96
96: ; preds = %91, %85
br label %97
97: ; preds = %96, %44
%98 = load i8*, i8** %6
store i8* %98, i8** %4
br label %99
99: ; preds = %97, %62, %28
%100 = load i8*, i8** %4
ret i8* %100
}

LLVM IR (-O2):
@.str = [220 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/shared_func.c, line: %d, filename length: %d is too long, exceeds %d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [220 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/shared_func.c, line: %d, call getcwd fail, errno: %d, error info: %s\00"
@errno = global i32 0
@.str.3 = [13 x i8] c"Unkown error\00"
@.str.4 = [6 x i8] c"%s/%s\00"
define i8* @getAbsolutePath(i8* %0, i8* %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %3
store i8 0, i8* %6
br label %28
11: ; preds = %3
%12 = ptrtoint i8* %8 to i64
%13 = ptrtoint i8* %0 to i64
%14 = sub i64 %12, %13
%15 = trunc i64 %14 to i32
%16 = and i64 %14, 4294966272
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %11
%19 = tail call i32 (i8*, i32, i32, ...) @logError(i8* getelementptr inbounds ([220 x i8], [220 x i8]* @.str, i64 0, i64 0), i32 118, i32 %15, i32 1024)
br label %56
20: ; preds = %11
%21 = and i64 %14, 4294967295
%22 = call i32 @memcpy(i8* %6, i8* %0, i32 %15)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %21
store i8 0, i8* %23
%24 = load i8, i8* %6
%25 = icmp eq i8 %24, 47
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %56
28: ; preds = %10, %20
%29 = call i32* @getcwd(i8* %7, i32 256)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %41
31: ; preds = %28
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = icmp eq i8* %33, null
br i1 %34, label %38, label %35
35: ; preds = %31
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
br label %38
38: ; preds = %31, %35
%39 = phi i8* [ %37, %35 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), %31 ]
%40 = call i32 (i8*, i32, i32, ...) @logError(i8* getelementptr inbounds ([220 x i8], [220 x i8]* @.str.2, i64 0, i64 0), i32 136, i32 %32, i8* %39)
br label %56
41: ; preds = %28
%42 = call i32 @strlen(i8* %7)
%43 = add nsw i32 %42, -1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = icmp eq i8 %46, 47
br i1 %47, label %48, label %49
48: ; preds = %41
store i8 0, i8* %45
br label %49
49: ; preds = %48, %41
%50 = load i8, i8* %6
%51 = icmp eq i8 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %49
%53 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %7, i8* %6)
br label %56
54: ; preds = %49
%55 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %56
56: ; preds = %26, %54, %52, %38, %18
%57 = phi i8* [ null, %38 ], [ null, %18 ], [ %1, %52 ], [ %1, %54 ], [ %1, %26 ]
ret i8* %57
}