#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 */
scalar_t__ malloc(size_t);
size_t strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
char *getAppPath(char app_name[]) {
  size_t name_size = strlen(app_name) + sizeof("/tmp/") + 1;
  char *filename = (char *)malloc(name_size);
  filename[0] = 0;
  strncat(filename, "/tmp/", name_size);
  strncat(filename, app_name, name_size - sizeof("/tmp/"));
  return filename;
}


x86 assembly (clang, -O0):
<getAppPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x6,%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
lea    0xe8a(%rip),%rsi
call   1040 <strncat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
sub    $0x6,%rax
mov    %eax,%edx
call   1040 <strncat@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAppPath>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%r12
lea    0x7(%rax),%r15
mov    %r15,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
lea    0xea4(%rip),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
call   1040 <strncat@plt>
add    $0x1,%r12d
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1040 <strncat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"/tmp/\00"
define i8* @getAppPath(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strlen(i8* %5)
%7 = add i64 %6, 6
%8 = add i64 %7, 1
store i64 %8, i64* %3
%9 = load i64, i64* %3
%10 = call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 0
store i8 0, i8* %13
%14 = load i8*, i8** %4
%15 = load i64, i64* %3
%16 = trunc i64 %15 to i32
%17 = call i32 @strncat(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i8*, i8** %4
%19 = load i8*, i8** %2
%20 = load i64, i64* %3
%21 = sub i64 %20, 6
%22 = trunc i64 %21 to i32
%23 = call i32 @strncat(i8* %18, i8* %19, i32 %22)
%24 = load i8*, i8** %4
ret i8* %24
}

LLVM IR (-O2):
@.str = [6 x i8] c"/tmp/\00"
define i8* @getAppPath(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, 7
%4 = tail call i64 @malloc(i64 %3)
%5 = inttoptr i64 %4 to i8*
store i8 0, i8* %5
%6 = trunc i64 %3 to i32
%7 = tail call i32 @strncat(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = trunc i64 %2 to i32
%9 = add i32 %8, 1
%10 = tail call i32 @strncat(i8* %5, i8* %0, i32 %9)
ret i8* %5
}