#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 *);
char *xmalloc(unsigned int);
char *docat(register char *s1, register char *s2) {
  register char *p;
  char *arg1, *arg2;
  if (!s1 && !s2)
    return (0);
  arg1 = s1 ? s1 : "";
  arg2 = s2 ? s2 : "";
  p = xmalloc((unsigned)(strlen(arg1) + strlen(arg2) + 1));
  (void)strcpy(p, arg1);
  (void)strcat(p, arg2);
  if (s1)
    xfree(s1);
  if (s2)
    xfree(s2);
  return (p);
}


x86 assembly (clang, -O0):
<docat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1183 <docat+0x33>
cmpq   $0x0,-0x18(%rbp)
jne    1183 <docat+0x33>
movq   $0x0,-0x8(%rbp)
jmp    125c <docat+0x10c>
cmpq   $0x0,-0x10(%rbp)
je     119b <docat+0x4b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    11ab <docat+0x5b>
lea    0xe5e(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    11ab <docat+0x5b>
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cb <docat+0x7b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    11db <docat+0x8b>
lea    0xe2e(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    11db <docat+0x8b>
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1060 <xmalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <strcat@plt>
cmpq   $0x0,-0x10(%rbp)
je     1240 <docat+0xf0>
mov    -0x10(%rbp),%rdi
call   1050 <xfree@plt>
cmpq   $0x0,-0x18(%rbp)
je     1254 <docat+0x104>
mov    -0x18(%rbp),%rdi
call   1050 <xfree@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<docat>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%rax
or     %rsi,%rax
je     11d3 <docat+0x83>
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
lea    0xe8f(%rip),%r12
mov    %r12,%r13
cmovne %rdi,%r13
test   %rsi,%rsi
cmovne %rsi,%r12
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    (%rax,%r15,1),%edi
add    $0x1,%edi
call   1060 <xmalloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <strcat@plt>
test   %rbx,%rbx
je     11c4 <docat+0x74>
mov    %rbx,%rdi
call   1050 <xfree@plt>
test   %r14,%r14
je     11d6 <docat+0x86>
mov    %r14,%rdi
call   1050 <xfree@plt>
jmp    11d6 <docat+0x86>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @docat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %11
store i8* null, i8** %3
br label %57
15: ; preds = %11, %2
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = load i8*, i8** %4
br label %21
20: ; preds = %15
br label %21
21: ; preds = %20, %18
%22 = phi i8* [ %19, %18 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %20 ]
store i8* %22, i8** %7
%23 = load i8*, i8** %5
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i8*, i8** %5
br label %28
27: ; preds = %21
br label %28
28: ; preds = %27, %25
%29 = phi i8* [ %26, %25 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %27 ]
store i8* %29, i8** %8
%30 = load i8*, i8** %7
%31 = call i64 @strlen(i8* %30)
%32 = load i8*, i8** %8
%33 = call i64 @strlen(i8* %32)
%34 = add nsw i64 %31, %33
%35 = add nsw i64 %34, 1
%36 = trunc i64 %35 to i32
%37 = call i8* @xmalloc(i32 %36)
store i8* %37, i8** %6
%38 = load i8*, i8** %6
%39 = load i8*, i8** %7
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = load i8*, i8** %6
%42 = load i8*, i8** %8
%43 = call i32 @strcat(i8* %41, i8* %42)
%44 = load i8*, i8** %4
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %49
46: ; preds = %28
%47 = load i8*, i8** %4
%48 = call i32 @xfree(i8* %47)
br label %49
49: ; preds = %46, %28
%50 = load i8*, i8** %5
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i8*, i8** %5
%54 = call i32 @xfree(i8* %53)
br label %55
55: ; preds = %52, %49
%56 = load i8*, i8** %6
store i8* %56, i8** %3
br label %57
57: ; preds = %55, %14
%58 = load i8*, i8** %3
ret i8* %58
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @docat(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %6, label %22
6: ; preds = %2
%7 = select i1 %3, i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
%8 = select i1 %4, i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %7)
%10 = tail call i64 @strlen(i8* dereferenceable(1) %8)
%11 = add nsw i64 %10, %9
%12 = trunc i64 %11 to i32
%13 = add i32 %12, 1
%14 = tail call i8* @xmalloc(i32 %13)
%15 = tail call i32 @strcpy(i8* %14, i8* %7)
%16 = tail call i32 @strcat(i8* %14, i8* %8)
br i1 %3, label %17, label %19
17: ; preds = %6
%18 = tail call i32 @xfree(i8* %0)
br label %19
19: ; preds = %17, %6
br i1 %4, label %20, label %22
20: ; preds = %19
%21 = tail call i32 @xfree(i8* %1)
br label %22
22: ; preds = %19, %20, %2
%23 = phi i8* [ null, %2 ], [ %14, %20 ], [ %14, %19 ]
ret i8* %23
}