#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*/ process_path;
typedef int /*<<< orphan*/ process_name;
typedef int /*<<< orphan*/ log_name;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ muggle_os_process_path(char *, int);
scalar_t__ muggle_path_basename(char *, char *, int);
scalar_t__ muggle_path_join(char *, char *, char *, size_t);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
int muggle_log_simple_init_log_path(char *log_path, size_t log_path_size) {
  char process_path[1024];
  if (muggle_os_process_path(process_path, sizeof(process_path)) != 0) {
    fprintf(stderr, "failed get process path");
    return -1;
  }
  char process_name[1024];
  if (muggle_path_basename(process_path, process_name, sizeof(process_name)) !=
      0) {
    fprintf(stderr, "failed get basename from path: %s", process_path);
    return -1;
  }
  char log_name[1024];
  snprintf(log_name, sizeof(log_name), "%s.log", process_name);
  if (muggle_path_join("log", log_name, log_path, log_path_size) != 0) {
    fprintf(stderr, "failed join log path");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<muggle_log_simple_init_log_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1040 <muggle_os_process_path@plt>
cmp    $0x0,%rax
je     11a1 <muggle_log_simple_init_log_path+0x51>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125b <muggle_log_simple_init_log_path+0x10b>
lea    -0x420(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    $0x400,%edx
call   1070 <muggle_path_basename@plt>
cmp    $0x0,%rax
je     11ed <muggle_log_simple_init_log_path+0x9d>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125b <muggle_log_simple_init_log_path+0x10b>
lea    -0xc20(%rbp),%rdi
lea    -0x820(%rbp),%rcx
mov    $0x400,%esi
lea    0xe33(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0xc20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe1b(%rip),%rdi
call   1030 <muggle_path_join@plt>
cmp    $0x0,%rax
je     1254 <muggle_log_simple_init_log_path+0x104>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125b <muggle_log_simple_init_log_path+0x10b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<muggle_log_simple_init_log_path>:
push   %r15
push   %r14
push   %rbx
sub    $0xc00,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x400,%esi
call   1040 <muggle_os_process_path@plt>
test   %rax,%rax
je     118d <muggle_log_simple_init_log_path+0x3d>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11c1 <muggle_log_simple_init_log_path+0x71>
mov    %rsp,%rdi
lea    0x400(%rsp),%rsi
mov    $0x400,%edx
call   1070 <muggle_path_basename@plt>
test   %rax,%rax
je     11d3 <muggle_log_simple_init_log_path+0x83>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0xc00,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe60(%rip),%rdx
lea    0x800(%rsp),%r15
lea    0x400(%rsp),%rcx
mov    %r15,%rdi
mov    $0x400,%esi
call   1050 <snprintf@plt>
lea    0xe3f(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <muggle_path_join@plt>
test   %rax,%rax
je     1226 <muggle_log_simple_init_log_path+0xd6>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
jmp    1184 <muggle_log_simple_init_log_path+0x34>
xor    %eax,%eax
jmp    11c6 <muggle_log_simple_init_log_path+0x76>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"failed get process path\00"
@.str.1 = [34 x i8] c"failed get basename from path: %s\00"
@.str.2 = [7 x i8] c"%s.log\00"
@.str.3 = [4 x i8] c"log\00"
@.str.4 = [21 x i8] c"failed join log path\00"
define i32 @muggle_log_simple_init_log_path(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
store i8* %0, i8** %4
store i64 %1, i64* %5
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = call i64 @muggle_os_process_path(i8* %9, i32 1024)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %37
15: ; preds = %2
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%18 = call i64 @muggle_path_basename(i8* %16, i8* %17, i32 1024)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %22)
store i32 -1, i32* %3
br label %37
24: ; preds = %15
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%27 = call i32 @snprintf(i8* %25, i32 1024, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%29 = load i8*, i8** %4
%30 = load i64, i64* %5
%31 = call i64 @muggle_path_join(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %28, i8* %29, i64 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %24
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %37
36: ; preds = %24
store i32 0, i32* %3
br label %37
37: ; preds = %36, %33, %20, %12
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"failed get process path\00"
@.str.1 = [34 x i8] c"failed get basename from path: %s\00"
@.str.2 = [7 x i8] c"%s.log\00"
@.str.3 = [4 x i8] c"log\00"
@.str.4 = [21 x i8] c"failed join log path\00"
define i32 @muggle_log_simple_init_log_path(i8* %0, i64 %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = call i64 @muggle_os_process_path(i8* %6, i32 1024)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %31
12: ; preds = %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = call i64 @muggle_path_basename(i8* %6, i8* %13, i32 1024)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %29
19: ; preds = %12
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%21 = call i32 @snprintf(i8* %20, i32 1024, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%22 = call i64 @muggle_path_join(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %20, i8* %0, i64 %1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %19, %24
%28 = phi i32 [ -1, %24 ], [ 0, %19 ]
br label %29
29: ; preds = %27, %16
%30 = phi i32 [ -1, %16 ], [ %28, %27 ]
br label %31
31: ; preds = %29, %9
%32 = phi i32 [ -1, %9 ], [ %30, %29 ]
ret i32 %32
}