void get_exec_name(char *exec_name, unsigned int exec_name_size) {
  char exec_path[512];
  int rc = readlink("/proc/self/exe", exec_path, sizeof(exec_path) - 1);
  if (rc < 0) {
    {
      if (!(0)) {
        {
          halt("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/baruch/traces/refs/heads/"
               "master/libtrace/trace_user.c",
               __FUNCTION__, 340);
        };
      }
    };
  }
  exec_path[rc] = '\0';
  strncpy(exec_name, basename(exec_path), exec_name_size);
}


x86 assembly (clang, -O0):
<get_exec_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x210(%rbp),%rsi
lea    0xea0(%rip),%rdi
mov    $0x1ff,%edx
mov    $0x0,%al
call   1040 <readlink@plt>
mov    %eax,-0x214(%rbp)
cmpl   $0x0,-0x214(%rbp)
jge    1199 <get_exec_name+0x59>
lea    0xe89(%rip),%rdi
lea    0xf12(%rip),%rsi
mov    $0x154,%edx
mov    $0x0,%al
call   1060 <halt@plt>
movslq -0x214(%rbp),%rax
movb   $0x0,-0x210(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
mov    %rax,-0x220(%rbp)
lea    -0x210(%rbp),%rdi
mov    $0x0,%al
call   1050 <basename@plt>
mov    -0x220(%rbp),%rdi
movslq %eax,%rsi
mov    -0xc(%rbp),%eax
mov    %eax,%edx
call   1030 <strncpy@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_exec_name>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xea9(%rip),%rdi
mov    %rsp,%rsi
mov    $0x1ff,%edx
xor    %eax,%eax
call   1040 <readlink@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1186 <get_exec_name+0x46>
lea    0xe9c(%rip),%rdi
lea    0xf25(%rip),%rsi
mov    $0x154,%edx
xor    %eax,%eax
call   1060 <halt@plt>
movslq %ebx,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
xor    %eax,%eax
call   1050 <basename@plt>
movslq %eax,%rsi
mov    %ebp,%edx
mov    %r14,%rdi
call   1030 <strncpy@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/proc/self/exe\00"
@.str.1 = [144 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/baruch/traces/refs/heads/master/libtrace/trace_user.c\00"
@__FUNCTION__.get_exec_name = [14 x i8] c"get_exec_name\00"
define void @get_exec_name(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%8 = call i32 (i8*, i8*, i64, ...) bitcast (i32 (...)* @readlink to i32 (i8*, i8*, i64, ...)*)(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %7, i64 511)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @halt to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__FUNCTION__.get_exec_name, i64 0, i64 0), i32 340)
br label %13
13: ; preds = %11, %2
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %15
store i8 0, i8* %16
%17 = load i8*, i8** %3
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%19 = call i32 (i8*, ...) bitcast (i32 (...)* @basename to i32 (i8*, ...)*)(i8* %18)
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i8*
%22 = load i32, i32* %4
%23 = zext i32 %22 to i64
%24 = call i8* @strncpy(i8* %17, i8* %21, i64 %23)
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"/proc/self/exe\00"
@.str.1 = [144 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/baruch/traces/refs/heads/master/libtrace/trace_user.c\00"
@__FUNCTION__.get_exec_name = [14 x i8] c"get_exec_name\00"
define void @get_exec_name(i8* %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = call i32 (i8*, i8*, i64, ...) bitcast (i32 (...)* @readlink to i32 (i8*, i8*, i64, ...)*)(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %4, i64 511)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @halt to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__FUNCTION__.get_exec_name, i64 0, i64 0), i32 340)
br label %9
9: ; preds = %7, %2
%10 = sext i32 %5 to i64
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i32 (i8*, ...) bitcast (i32 (...)* @basename to i32 (i8*, ...)*)(i8* %4)
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i8*
%15 = zext i32 %1 to i64
%16 = call i8* @strncpy(i8* dereferenceable(1) %0, i8* %14, i64 %15)
ret void
}