#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 *malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ yap_quit(char *);
char *yap_makename(char *stem, char *ext) {
  char *savefile;
  if (!ext)
    ext = "";
  savefile = malloc(strlen(stem) + 1 + strlen(ext));
  if (!savefile)
    yap_quit("Cannot allocate filename string\n");
  strcpy(savefile, stem);
  strcat(savefile, ext);
  return savefile;
}


x86 assembly (clang, -O0):
<yap_makename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1176 <yap_makename+0x26>
lea    0xeae(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b7 <yap_makename+0x67>
lea    0xe4e(%rip),%rdi
call   1060 <yap_quit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yap_makename>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
test   %rsi,%rsi
lea    0xebe(%rip),%r15
cmovne %rsi,%r15
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1197 <yap_makename+0x47>
lea    0xe6e(%rip),%rdi
call   1060 <yap_quit@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [33 x i8] c"Cannot allocate filename string\0A\00"
define i8* @yap_makename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %4
br label %9
9: ; preds = %8, %2
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %11, 1
%13 = load i8*, i8** %4
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %12, %14
%16 = call i8* @malloc(i64 %15)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = icmp ne i8* %17, null
br i1 %18, label %21, label %19
19: ; preds = %9
%20 = call i32 @yap_quit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %9
%22 = load i8*, i8** %5
%23 = load i8*, i8** %3
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %5
%26 = load i8*, i8** %4
%27 = call i32 @strcat(i8* %25, i8* %26)
%28 = load i8*, i8** %5
ret i8* %28
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [33 x i8] c"Cannot allocate filename string\0A\00"
define i8* @yap_makename(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
%4 = select i1 %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %1
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = add nsw i64 %5, 1
%7 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%8 = add nsw i64 %6, %7
%9 = tail call i8* @malloc(i64 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @yap_quit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = tail call i32 @strcpy(i8* %9, i8* %0)
%15 = tail call i32 @strcat(i8* %9, i8* %4)
ret i8* %9
}