#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int chdir(char *);
int readlink(char *, char *, int);
char *strrchr(char *, char);
void initialize_path(void) {
  char path[256];
  ssize_t bytes;
  int error;
  bytes = readlink("/proc/self/exe", path, 256 - 1);
  assert(bytes != -1);
  path[bytes] = '\0';
  *strrchr(path, '/') = '\0';
  error = chdir(path);
  assert(error == 0);
  error = chdir("assets");
  assert(error == 0);
  ((void)(error));
}


x86 assembly (clang, -O0):
<initialize_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    -0x100(%rbp),%rsi
lea    0xea7(%rip),%rdi
mov    $0xff,%edx
call   1030 <readlink@plt>
mov    %eax,-0x104(%rbp)
cmpl   $0xffffffff,-0x104(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movslq -0x104(%rbp),%rax
movb   $0x0,-0x100(%rbp,%rax,1)
lea    -0x100(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
movb   $0x0,(%rax)
lea    -0x100(%rbp),%rdi
call   1040 <chdir@plt>
mov    %eax,-0x108(%rbp)
cmpl   $0x0,-0x108(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xe42(%rip),%rdi
call   1040 <chdir@plt>
mov    %eax,-0x108(%rbp)
cmpl   $0x0,-0x108(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initialize_path>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
lea    0xeb0(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
mov    $0xff,%edx
call   1030 <readlink@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1060 <assert@plt>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1040 <chdir@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
lea    0xe6c(%rip),%rdi
call   1040 <chdir@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/proc/self/exe\00"
@.str.1 = [7 x i8] c"assets\00"
define void @initialize_path() {
%1 = alloca [256 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%5 = call i32 @readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %4, i32 255)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, -1
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %11
store i8 0, i8* %12
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%14 = call i8* @strrchr(i8* %13, i8 signext 47)
store i8 0, i8* %14
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%16 = call i32 @chdir(i8* %15)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = call i32 @chdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, 0
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32, i32* %3
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"/proc/self/exe\00"
@.str.1 = [7 x i8] c"assets\00"
define void @initialize_path() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = call i32 @readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %2, i32 255)
%4 = icmp ne i32 %3, -1
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = sext i32 %3 to i64
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %7
store i8 0, i8* %8
%9 = call i8* @strrchr(i8* %2, i8 signext 47)
store i8 0, i8* %9
%10 = call i32 @chdir(i8* %2)
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = call i32 @chdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
ret void
}