#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);
char *strdup(char *);
size_t strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, size_t);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *merge(char *s1, char *s2, int use_space) {
  if (s1 == NULL) {
    return strdup(s2);
  } else {
    size_t l1 = strlen(s1);
    size_t l2 = strlen(s2);
    size_t len = l1 + l2 + 2;
    char *temp = (char *)malloc(len);
    strncpy(temp, s1, len);
    if (use_space)
      strncat(temp, " ", len);
    strncat(temp, s2, len);
    return temp;
  }
}


x86 assembly (clang, -O0):
<merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1180 <merge+0x30>
mov    -0x18(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11ff <merge+0xaf>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
add    -0x30(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1030 <strncpy@plt>
cmpl   $0x0,-0x1c(%rbp)
je     11e6 <merge+0x96>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xe1f(%rip),%rsi
call   1050 <strncat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1050 <strncat@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
test   %rdi,%rdi
je     11c8 <merge+0x78>
mov    %edx,%r14d
mov    %rdi,%rbp
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%r12
add    $0x2,%r12
mov    %r12,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1030 <strncpy@plt>
test   %r14d,%r14d
je     11ae <merge+0x5e>
lea    0xe5d(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
call   1050 <strncat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <strncat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <strdup@plt>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i8* @merge(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = call i8* @strdup(i8* %15)
store i8* %16, i8** %4
br label %45
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = call i64 @strlen(i8* %18)
store i64 %19, i64* %8
%20 = load i8*, i8** %6
%21 = call i64 @strlen(i8* %20)
store i64 %21, i64* %9
%22 = load i64, i64* %8
%23 = load i64, i64* %9
%24 = add i64 %22, %23
%25 = add i64 %24, 2
store i64 %25, i64* %10
%26 = load i64, i64* %10
%27 = call i64 @malloc(i64 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %11
%29 = load i8*, i8** %11
%30 = load i8*, i8** %5
%31 = load i64, i64* %10
%32 = call i32 @strncpy(i8* %29, i8* %30, i64 %31)
%33 = load i32, i32* %7
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %17
%36 = load i8*, i8** %11
%37 = load i64, i64* %10
%38 = call i32 @strncat(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64 %37)
br label %39
39: ; preds = %35, %17
%40 = load i8*, i8** %11
%41 = load i8*, i8** %6
%42 = load i64, i64* %10
%43 = call i32 @strncat(i8* %40, i8* %41, i64 %42)
%44 = load i8*, i8** %11
store i8* %44, i8** %4
br label %45
45: ; preds = %39, %14
%46 = load i8*, i8** %4
ret i8* %46
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i8* @merge(i8* %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i8* @strdup(i8* %1)
br label %20
7: ; preds = %3
%8 = tail call i64 @strlen(i8* %0)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%10 = add i64 %8, 2
%11 = add i64 %10, %9
%12 = tail call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 @strncpy(i8* %13, i8* %0, i64 %11)
%15 = icmp eq i32 %2, 0
br i1 %15, label %18, label %16
16: ; preds = %7
%17 = tail call i32 @strncat(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64 %11)
br label %18
18: ; preds = %16, %7
%19 = tail call i32 @strncat(i8* %13, i8* %1, i64 %11)
br label %20
20: ; preds = %18, %5
%21 = phi i8* [ %6, %5 ], [ %13, %18 ]
ret i8* %21
}