#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 */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_exec_path(char *, int);
int lastIndexOf(char *, char *);
int /*<<< orphan*/ log_info(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ substr(char *, int, char *, int);
char *get_root() {
  int bufsize = 1023;
  char *buf = calloc(bufsize, sizeof(char));
  char *root = calloc(bufsize, sizeof(char));
  get_exec_path(buf, bufsize);
  int index = lastIndexOf(buf, "/");
  substr(root, bufsize, buf, index);
  strcat(root, "/../../../html");
  log_info("Setting root: %s", root);
  free(buf);
  return root;
}


x86 assembly (clang, -O0):
<get_root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x3ff,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1060 <get_exec_path@plt>
mov    -0x10(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1080 <lastIndexOf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1050 <substr@plt>
mov    -0x18(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x18(%rbp),%rsi
lea    0xe23(%rip),%rdi
call   1040 <log_info@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_root>:
push   %r14
push   %rbx
push   %rax
mov    $0x3ff,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r14
mov    $0x3ff,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x3ff,%esi
call   1060 <get_exec_path@plt>
lea    0xe54(%rip),%rsi
mov    %r14,%rdi
call   1080 <lastIndexOf@plt>
mov    %rbx,%rdi
mov    $0x3ff,%esi
mov    %r14,%rdx
mov    %eax,%ecx
call   1050 <substr@plt>
lea    0xe35(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
lea    0xe35(%rip),%rdi
mov    %rbx,%rsi
call   1040 <log_info@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [15 x i8] c"/../../../html\00"
@.str.2 = [17 x i8] c"Setting root: %s\00"
define i8* @get_root() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i32 1023, i32* %1
%5 = load i32, i32* %1
%6 = call i8* @calloc(i32 %5, i32 1)
store i8* %6, i8** %2
%7 = load i32, i32* %1
%8 = call i8* @calloc(i32 %7, i32 1)
store i8* %8, i8** %3
%9 = load i8*, i8** %2
%10 = load i32, i32* %1
%11 = call i32 @get_exec_path(i8* %9, i32 %10)
%12 = load i8*, i8** %2
%13 = call i32 @lastIndexOf(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %4
%14 = load i8*, i8** %3
%15 = load i32, i32* %1
%16 = load i8*, i8** %2
%17 = load i32, i32* %4
%18 = call i32 @substr(i8* %14, i32 %15, i8* %16, i32 %17)
%19 = load i8*, i8** %3
%20 = call i32 @strcat(i8* %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%21 = load i8*, i8** %3
%22 = call i32 @log_info(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %2
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %3
ret i8* %25
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [15 x i8] c"/../../../html\00"
@.str.2 = [17 x i8] c"Setting root: %s\00"
define i8* @get_root() {
%1 = tail call dereferenceable_or_null(1023) i8* @calloc(i32 1023, i32 1)
%2 = tail call dereferenceable_or_null(1023) i8* @calloc(i32 1023, i32 1)
%3 = tail call i32 @get_exec_path(i8* %1, i32 1023)
%4 = tail call i32 @lastIndexOf(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @substr(i8* %2, i32 1023, i8* %1, i32 %4)
%6 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @log_info(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%8 = tail call i32 @free(i8* %1)
ret i8* %2
}