#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 S_IRUSR;
int S_IWUSR;
int S_IXUSR;
int /*<<< orphan*/ chmod(char *, int);
char *get_memo_conf_value(char *);
char *get_memo_default_path();
scalar_t__ malloc(int);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *get_memo_file_path(char *category) {
  char *path = get_memo_conf_value("STAMP_PATH");
  if (!path)
    path = get_memo_default_path();
  mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR);
  chmod(path, 0700);
  if (strlen(category) == 0)
    return path;
  char *cat_path =
      (char *)malloc((strlen(path) + strlen(category) + 2) * sizeof(char));
  strcpy(cat_path, path);
  strcat(cat_path, "/");
  strcat(cat_path, category);
  return cat_path;
}


x86 assembly (clang, -O0):
<get_memo_file_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe6d(%rip),%rdi
call   10a0 <get_memo_conf_value@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b2 <get_memo_file_path+0x32>
mov    $0x0,%al
call   1060 <get_memo_default_path@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
mov    0x2e1a(%rip),%rax
or     (%rax),%esi
mov    0x2e19(%rip),%rax
or     (%rax),%esi
call   1040 <mkdir@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1c0,%esi
call   1080 <chmod@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jne    1203 <get_memo_file_path+0x83>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1265 <get_memo_file_path+0xe5>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xdc0(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_memo_file_path>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe71(%rip),%rdi
call   10a0 <get_memo_conf_value@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a6 <get_memo_file_path+0x26>
xor    %eax,%eax
call   1060 <get_memo_default_path@plt>
mov    %rax,%rbx
mov    0x2e23(%rip),%rax
mov    0x2e2c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e29(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   1040 <mkdir@plt>
mov    %rbx,%rdi
mov    $0x1c0,%esi
call   1080 <chmod@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     122c <get_memo_file_path+0xac>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xdf5(%rip),%rsi
mov    %r15,%rdi
call   1090 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1090 <strcat@plt>
mov    %r15,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"STAMP_PATH\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@.str.1 = [2 x i8] c"/\00"
define i8* @get_memo_file_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = call i8* @get_memo_conf_value(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = call i8* (...) @get_memo_default_path()
store i8* %10, i8** %4
br label %11
11: ; preds = %9, %1
%12 = load i8*, i8** %4
%13 = load i32, i32* @S_IRUSR
%14 = load i32, i32* @S_IWUSR
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IXUSR
%17 = or i32 %15, %16
%18 = call i32 @mkdir(i8* %12, i32 %17)
%19 = load i8*, i8** %4
%20 = call i32 @chmod(i8* %19, i32 448)
%21 = load i8*, i8** %3
%22 = call i32 @strlen(i8* %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %11
%25 = load i8*, i8** %4
store i8* %25, i8** %2
br label %47
26: ; preds = %11
%27 = load i8*, i8** %4
%28 = call i32 @strlen(i8* %27)
%29 = load i8*, i8** %3
%30 = call i32 @strlen(i8* %29)
%31 = add nsw i32 %28, %30
%32 = add nsw i32 %31, 2
%33 = sext i32 %32 to i64
%34 = mul i64 %33, 1
%35 = trunc i64 %34 to i32
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %5
%38 = load i8*, i8** %5
%39 = load i8*, i8** %4
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = load i8*, i8** %5
%42 = call i32 @strcat(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%43 = load i8*, i8** %5
%44 = load i8*, i8** %3
%45 = call i32 @strcat(i8* %43, i8* %44)
%46 = load i8*, i8** %5
store i8* %46, i8** %2
br label %47
47: ; preds = %26, %24
%48 = load i8*, i8** %2
ret i8* %48
}

LLVM IR (-O2):
@.str = [11 x i8] c"STAMP_PATH\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@.str.1 = [2 x i8] c"/\00"
define i8* @get_memo_file_path(i8* %0) {
%2 = tail call i8* @get_memo_conf_value(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i8* (...) @get_memo_default_path()
br label %6
6: ; preds = %4, %1
%7 = phi i8* [ %2, %1 ], [ %5, %4 ]
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %9, %8
%11 = load i32, i32* @S_IXUSR
%12 = or i32 %10, %11
%13 = tail call i32 @mkdir(i8* %7, i32 %12)
%14 = tail call i32 @chmod(i8* %7, i32 448)
%15 = tail call i32 @strlen(i8* %0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %27, label %17
17: ; preds = %6
%18 = tail call i32 @strlen(i8* %7)
%19 = tail call i32 @strlen(i8* %0)
%20 = add i32 %18, 2
%21 = add i32 %20, %19
%22 = tail call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = tail call i32 @strcpy(i8* %23, i8* %7)
%25 = tail call i32 @strcat(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = tail call i32 @strcat(i8* %23, i8* %0)
br label %27
27: ; preds = %6, %17
%28 = phi i8* [ %23, %17 ], [ %7, %6 ]
ret i8* %28
}