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


x86 assembly (clang, -O0):
<xstrmerge1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1193 <xstrmerge1+0x33>
cmpq   $0x0,-0x18(%rbp)
jne    1193 <xstrmerge1+0x33>
movq   $0x0,-0x8(%rbp)
jmp    121d <xstrmerge1+0xbd>
cmpq   $0x0,-0x10(%rbp)
jne    11b0 <xstrmerge1+0x50>
mov    -0x18(%rbp),%rdi
call   1070 <xstrdup@plt>
mov    %rax,-0x8(%rbp)
jmp    121d <xstrmerge1+0xbd>
cmpq   $0x0,-0x18(%rbp)
jne    11c8 <xstrmerge1+0x68>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121d <xstrmerge1+0xbd>
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   1080 <strcat@plt>
mov    -0x10(%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):
<xstrmerge1>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rax
or     %rsi,%rax
jne    1171 <xstrmerge1+0x11>
xor    %ebx,%ebx
jmp    11c5 <xstrmerge1+0x65>
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     11ce <xstrmerge1+0x6e>
test   %r14,%r14
je     11c5 <xstrmerge1+0x65>
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   1060 <xmalloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
call   1050 <xfree@plt>
mov    %r15,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <xstrdup@plt>

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

LLVM IR (-O2):
define i8* @xstrmerge1(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 %20, label %6
6: ; preds = %2
br i1 %3, label %7, label %9
7: ; preds = %6
%8 = tail call i8* @xstrdup(i8* %1)
br label %20
9: ; preds = %6
br i1 %4, label %20, label %10
10: ; preds = %9
%11 = tail call i64 @strlen(i8* %0)
%12 = tail call i64 @strlen(i8* %1)
%13 = add i64 %11, 1
%14 = add i64 %13, %12
%15 = tail call i64 @xmalloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 @strcpy(i8* %16, i8* %0)
%18 = tail call i32 @strcat(i8* %16, i8* %1)
%19 = tail call i32 @xfree(i8* %0)
br label %20
20: ; preds = %9, %2, %10, %7
%21 = phi i8* [ %8, %7 ], [ %16, %10 ], [ null, %2 ], [ %0, %9 ]
ret i8* %21
}