#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*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
scalar_t__ xmalloc(scalar_t__);
char *xstrdup(char const *);
char *xstrmerge2(char const *str1, char const *str2) {
  char *res;
  if (str1 == NULL && str2 == NULL)
    return NULL;
  if (str1 == NULL)
    return xstrdup(str2);
  if (str2 == NULL)
    return xstrdup(str1);
  res = (char *)xmalloc(strlen(str1) + strlen(str2) + 1);
  strcpy(res, str1);
  strcat(res, str2);
  return res;
}


x86 assembly (clang, -O0):
<xstrmerge2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1183 <xstrmerge2+0x33>
cmpq   $0x0,-0x18(%rbp)
jne    1183 <xstrmerge2+0x33>
movq   $0x0,-0x8(%rbp)
jmp    1209 <xstrmerge2+0xb9>
cmpq   $0x0,-0x10(%rbp)
jne    11a0 <xstrmerge2+0x50>
mov    -0x18(%rbp),%rdi
call   1060 <xstrdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1209 <xstrmerge2+0xb9>
cmpq   $0x0,-0x18(%rbp)
jne    11bd <xstrmerge2+0x6d>
mov    -0x10(%rbp),%rdi
call   1060 <xstrdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1209 <xstrmerge2+0xb9>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <xmalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrmerge2>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rax
or     %rsi,%rax
jne    1162 <xstrmerge2+0x12>
xor    %r15d,%r15d
jmp    11ab <xstrmerge2+0x5b>
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     11b4 <xstrmerge2+0x64>
test   %r14,%r14
je     11b9 <xstrmerge2+0x69>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x1,%rdi
call   1050 <xmalloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
jmp    11bc <xstrmerge2+0x6c>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <xstrdup@plt>

LLVM IR (-O0):
define i8* @xstrmerge2(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %9
store i8* null, i8** %3
br label %41
13: ; preds = %9, %2
%14 = load i8*, i8** %4
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = call i8* @xstrdup(i8* %17)
store i8* %18, i8** %3
br label %41
19: ; preds = %13
%20 = load i8*, i8** %5
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = call i8* @xstrdup(i8* %23)
store i8* %24, i8** %3
br label %41
25: ; preds = %19
%26 = load i8*, i8** %4
%27 = call i64 @strlen(i8* %26)
%28 = load i8*, i8** %5
%29 = call i64 @strlen(i8* %28)
%30 = add nsw i64 %27, %29
%31 = add nsw i64 %30, 1
%32 = call i64 @xmalloc(i64 %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %6
%34 = load i8*, i8** %6
%35 = load i8*, i8** %4
%36 = call i32 @strcpy(i8* %34, i8* %35)
%37 = load i8*, i8** %6
%38 = load i8*, i8** %5
%39 = call i32 @strcat(i8* %37, i8* %38)
%40 = load i8*, i8** %6
store i8* %40, i8** %3
br label %41
41: ; preds = %25, %22, %16, %12
%42 = load i8*, i8** %3
ret i8* %42
}

LLVM IR (-O2):
define i8* @xstrmerge2(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %21, label %6
6: ; preds = %2
br i1 %3, label %7, label %9
7: ; preds = %6
%8 = tail call i8* @xstrdup(i8* %1)
br label %21
9: ; preds = %6
br i1 %4, label %10, label %12
10: ; preds = %9
%11 = tail call i8* @xstrdup(i8* %0)
br label %21
12: ; preds = %9
%13 = tail call i64 @strlen(i8* %0)
%14 = tail call i64 @strlen(i8* %1)
%15 = add i64 %13, 1
%16 = add i64 %15, %14
%17 = tail call i64 @xmalloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
%19 = tail call i32 @strcpy(i8* %18, i8* %0)
%20 = tail call i32 @strcat(i8* %18, i8* %1)
br label %21
21: ; preds = %2, %12, %10, %7
%22 = phi i8* [ %8, %7 ], [ %11, %10 ], [ %18, %12 ], [ null, %2 ]
ret i8* %22
}