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


x86 assembly (clang, -O0):
<xstrmerge0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1183 <xstrmerge0+0x33>
cmpq   $0x0,-0x18(%rbp)
jne    1183 <xstrmerge0+0x33>
movq   $0x0,-0x8(%rbp)
jmp    1211 <xstrmerge0+0xc1>
cmpq   $0x0,-0x10(%rbp)
jne    119b <xstrmerge0+0x4b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1211 <xstrmerge0+0xc1>
cmpq   $0x0,-0x18(%rbp)
jne    11b3 <xstrmerge0+0x63>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1211 <xstrmerge0+0xc1>
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   1060 <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    -0x10(%rbp),%rdi
call   1050 <xfree@plt>
mov    -0x18(%rbp),%rdi
call   1050 <xfree@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrmerge0>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
cmove  %rsi,%rbx
je     11b2 <xstrmerge0+0x62>
mov    %rsi,%r14
test   %rsi,%rsi
je     11b2 <xstrmerge0+0x62>
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1060 <xmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %r15,%rdi
call   1050 <xfree@plt>
mov    %r14,%rdi
call   1050 <xfree@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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