#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*/ szFileName;

/* Variables and functions */
int GetLastCharOccur(char *, char);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ readlink(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *GetFullPath() {
  static char szRet[2048];
  int lastPos;
  char szFileName[2048];
  memset(szFileName, 0, 2048);
  readlink("/proc/self/exe", szFileName, sizeof(szFileName));
  lastPos = GetLastCharOccur(szFileName, '/');
  memset(szRet, 0, 2048);
  strncpy(szRet, szFileName, lastPos + 1);
  return szRet;
}


x86 assembly (clang, -O0):
<GetFullPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1050 <memset@plt>
lea    -0x810(%rbp),%rsi
lea    0xe94(%rip),%rdi
mov    $0x800,%edx
call   1040 <readlink@plt>
lea    -0x810(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <GetLastCharOccur@plt>
mov    %eax,-0x4(%rbp)
lea    0x2ebf(%rip),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1050 <memset@plt>
lea    -0x810(%rbp),%rsi
mov    -0x4(%rbp),%edx
add    $0x1,%edx
lea    0x2e9f(%rip),%rdi
call   1030 <strncpy@plt>
lea    0x2e93(%rip),%rax
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetFullPath>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1050 <memset@plt>
lea    0xe9c(%rip),%rdi
mov    %r14,%rsi
mov    $0x800,%edx
call   1040 <readlink@plt>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1060 <GetLastCharOccur@plt>
mov    %eax,%ebp
lea    0x2ec9(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1050 <memset@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@GetFullPath.szRet = internal global [2048 x i8] zeroinitializer
@.str = [15 x i8] c"/proc/self/exe\00"
define i8* @GetFullPath() {
%1 = alloca i32
%2 = alloca [2048 x i8]
%3 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 2048)
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%6 = call i32 @readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %5, i32 2048)
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%8 = call i32 @GetLastCharOccur(i8* %7, i8 signext 47)
store i32 %8, i32* %1
%9 = call i32 @memset(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @GetFullPath.szRet, i64 0, i64 0), i32 0, i32 2048)
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%11 = load i32, i32* %1
%12 = add nsw i32 %11, 1
%13 = call i32 @strncpy(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @GetFullPath.szRet, i64 0, i64 0), i8* %10, i32 %12)
ret i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @GetFullPath.szRet, i64 0, i64 0)
}

LLVM IR (-O2):
@GetFullPath.szRet = internal global [2048 x i8] zeroinitializer
@.str = [15 x i8] c"/proc/self/exe\00"
define i8* @GetFullPath() {
%1 = alloca [2048 x i8]
%2 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 0, i32 2048)
%4 = call i32 @readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %2, i32 2048)
%5 = call i32 @GetLastCharOccur(i8* %2, i8 signext 47)
%6 = call i32 @memset(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @GetFullPath.szRet, i64 0, i64 0), i32 0, i32 2048)
%7 = add nsw i32 %5, 1
%8 = call i32 @strncpy(i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @GetFullPath.szRet, i64 0, i64 0), i8* %2, i32 %7)
ret i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @GetFullPath.szRet, i64 0, i64 0)
}