#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 */
int readlink(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int get_my_name(char *file_name, int len) {
  if (NULL == file_name || len < 0) {
    return -1;
  }
  int ret = readlink("/proc/self/exe", file_name, len);
  if (ret < 0) {
    return -1;
  }
  file_name[ret] = '\0';
  strcat(file_name, ".log");
  return 0;
}


x86 assembly (clang, -O0):
<get_my_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     1145 <get_my_name+0x25>
cmpl   $0x0,-0x14(%rbp)
jge    1151 <get_my_name+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <get_my_name+0x80>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xea1(%rip),%rdi
call   1030 <readlink@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    117d <get_my_name+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <get_my_name+0x80>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1040 <strcat@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_my_name>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     1160 <get_my_name+0x40>
mov    %esi,%edx
test   %esi,%esi
js     1160 <get_my_name+0x40>
mov    %rdi,%rbx
lea    0xec3(%rip),%rdi
mov    %rbx,%rsi
call   1030 <readlink@plt>
test   %eax,%eax
js     1160 <get_my_name+0x40>
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
lea    0xeb9(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/proc/self/exe\00"
@.str.1 = [5 x i8] c".log\00"
define i32 @get_my_name(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = icmp eq i8* null, %7
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9, %2
store i32 -1, i32* %3
br label %27
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = call i32 @readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 -1, i32* %3
br label %27
20: ; preds = %13
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
%25 = load i8*, i8** %4
%26 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %27
27: ; preds = %20, %19, %12
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [15 x i8] c"/proc/self/exe\00"
@.str.1 = [5 x i8] c".log\00"
define i32 @get_my_name(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
%4 = icmp slt i32 %1, 0
%5 = or i1 %3, %4
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = tail call i32 @readlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%8 = icmp slt i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = zext i32 %7 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 0, i8* %11
%12 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %9, %6, %2
%14 = phi i32 [ -1, %2 ], [ 0, %9 ], [ -1, %6 ]
ret i32 %14
}