#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 /*<<< orphan*/ free(char *);
char *getApplicationCommandLineTemplate(char *, char **, char **, char **,
                                        size_t);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ sprintf(char *, char *, char *);
size_t strlen(char *);
char *getApplicationCommandLine(char *application, char *filename,
                                char *known[], char *xterm[], char *opencmd[],
                                size_t total) {
  char *template;
  char *result;
  size_t totalSize;
  template = getApplicationCommandLineTemplate(application, known, xterm,
                                               opencmd, total);
  totalSize = strlen(template) + strlen(filename);
  result = (char *)malloc((size_t)(totalSize + 1));
  sprintf(result, template, filename);
  free(template);
  return result;
}


x86 assembly (clang, -O0):
<getApplicationCommandLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1050 <getApplicationCommandLineTemplate@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1070 <sprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getApplicationCommandLine>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8,%rcx
mov    %r9,%r8
call   1050 <getApplicationCommandLineTemplate@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1070 <sprintf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @getApplicationCommandLine(i8* %0, i8* %1, i8** %2, i8** %3, i8** %4, i64 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i8**
%11 = alloca i8**
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i64
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8** %2, i8*** %9
store i8** %3, i8*** %10
store i8** %4, i8*** %11
store i64 %5, i64* %12
%16 = load i8*, i8** %7
%17 = load i8**, i8*** %9
%18 = load i8**, i8*** %10
%19 = load i8**, i8*** %11
%20 = load i64, i64* %12
%21 = call i8* @getApplicationCommandLineTemplate(i8* %16, i8** %17, i8** %18, i8** %19, i64 %20)
store i8* %21, i8** %13
%22 = load i8*, i8** %13
%23 = call i64 @strlen(i8* %22)
%24 = load i8*, i8** %8
%25 = call i64 @strlen(i8* %24)
%26 = add i64 %23, %25
store i64 %26, i64* %15
%27 = load i64, i64* %15
%28 = add i64 %27, 1
%29 = call i64 @malloc(i64 %28)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %14
%31 = load i8*, i8** %14
%32 = load i8*, i8** %13
%33 = load i8*, i8** %8
%34 = call i32 @sprintf(i8* %31, i8* %32, i8* %33)
%35 = load i8*, i8** %13
%36 = call i32 @free(i8* %35)
%37 = load i8*, i8** %14
ret i8* %37
}

LLVM IR (-O2):
define i8* @getApplicationCommandLine(i8* %0, i8* %1, i8** %2, i8** %3, i8** %4, i64 %5) {
%7 = tail call i8* @getApplicationCommandLineTemplate(i8* %0, i8** %2, i8** %3, i8** %4, i64 %5)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %7)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%10 = add i64 %8, 1
%11 = add i64 %10, %9
%12 = tail call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) %7, i8* %1)
%15 = tail call i32 @free(i8* %7)
ret i8* %13
}