#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 *getenv(char *);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int strlen(char *);
char *get_logdir() {
  char *logdir;
  char *yannkinsDir = getenv("YANNKINS_HOME");
  if (yannkinsDir == NULL) {
    yannkinsDir = "/var/yannkins";
  }
  logdir = malloc((strlen(yannkinsDir) + strlen("log") + 2) * sizeof(char));
  if (logdir != NULL) {
    sprintf(logdir, "%s/%s", yannkinsDir, "log");
  }
  return logdir;
}


x86 assembly (clang, -O0):
<get_logdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116e <get_logdir+0x2e>
lea    0xea4(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
lea    0xe9b(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11c7 <get_logdir+0x87>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe65(%rip),%rsi
lea    0xe5a(%rip),%rcx
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_logdir>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xeb4(%rip),%r14
cmovne %rax,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xead(%rip),%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a0 <get_logdir+0x60>
lea    0xe92(%rip),%rsi
lea    0xe87(%rip),%rcx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"YANNKINS_HOME\00"
@.str.1 = [14 x i8] c"/var/yannkins\00"
@.str.2 = [4 x i8] c"log\00"
@.str.3 = [6 x i8] c"%s/%s\00"
define i8* @get_logdir() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %7
6: ; preds = %0
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %7
7: ; preds = %6, %0
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%11 = add nsw i32 %9, %10
%12 = add nsw i32 %11, 2
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %1
%17 = load i8*, i8** %1
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %7
%20 = load i8*, i8** %1
%21 = load i8*, i8** %2
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %19, %7
%24 = load i8*, i8** %1
ret i8* %24
}

LLVM IR (-O2):
@.str = [14 x i8] c"YANNKINS_HOME\00"
@.str.1 = [14 x i8] c"/var/yannkins\00"
@.str.2 = [4 x i8] c"log\00"
@.str.3 = [6 x i8] c"%s/%s\00"
define noalias i8* @get_logdir() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
%3 = select i1 %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %1
%4 = tail call i32 @strlen(i8* %3)
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%6 = add i32 %4, 2
%7 = add i32 %6, %5
%8 = tail call i8* @malloc(i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = tail call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
ret i8* %8
}