#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*/ diagnostics(int, char *, ...);
scalar_t__ malloc(size_t);
char *my_strdup(char const *);
int /*<<< orphan*/ my_strlcat(char *, char const *, size_t);
int /*<<< orphan*/ my_strlcpy(char *, char const *, size_t);
int strlen(char const *);
char *strdup_together(const char *s, const char *t) {
  char *both;
  size_t siz;
  if (s == NULL) {
    if (t == NULL)
      return NULL;
    return my_strdup(t);
  }
  if (t == NULL)
    return my_strdup(s);
  if (0)
    diagnostics(1, "'%s' + '%s'", s, t);
  siz = strlen(s) + strlen(t) + 1;
  both = (char *)malloc(siz);
  if (both == NULL)
    diagnostics(0, "Could not allocate memory for both strings.");
  my_strlcpy(both, s, siz);
  my_strlcat(both, t, siz);
  return both;
}


x86 assembly (clang, -O0):
<strdup_together>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a5 <strdup_together+0x45>
cmpq   $0x0,-0x18(%rbp)
jne    1193 <strdup_together+0x33>
movq   $0x0,-0x8(%rbp)
jmp    1239 <strdup_together+0xd9>
mov    -0x18(%rbp),%rdi
call   1080 <my_strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1239 <strdup_together+0xd9>
cmpq   $0x0,-0x18(%rbp)
jne    11c2 <strdup_together+0x62>
mov    -0x10(%rbp),%rdi
call   1080 <my_strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1239 <strdup_together+0xd9>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    120f <strdup_together+0xaf>
xor    %edi,%edi
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1060 <diagnostics@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <my_strlcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <my_strlcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strdup_together>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     11d2 <strdup_together+0x72>
mov    %rdi,%rbx
test   %r14,%r14
je     11dc <strdup_together+0x7c>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %r15d,%eax
add    $0x1,%eax
movslq %eax,%r12
mov    %r12,%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11b4 <strdup_together+0x54>
lea    0xe55(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1060 <diagnostics@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1050 <my_strlcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1030 <my_strlcat@plt>
jmp    11f2 <strdup_together+0x92>
test   %r14,%r14
je     11ef <strdup_together+0x8f>
mov    %r14,%rdi
jmp    11df <strdup_together+0x7f>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1080 <my_strdup@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [44 x i8] c"Could not allocate memory for both strings.\00"
define i8* @strdup_together(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
br i1 %3, label %5, label %8
5: ; preds = %2
br i1 %4, label %25, label %6
6: ; preds = %5
%7 = tail call i8* @my_strdup(i8* %1)
br label %25
8: ; preds = %2
br i1 %4, label %9, label %11
9: ; preds = %8
%10 = tail call i8* @my_strdup(i8* %0)
br label %25
11: ; preds = %8
%12 = tail call i32 @strlen(i8* %0)
%13 = tail call i32 @strlen(i8* %1)
%14 = add i32 %12, 1
%15 = add i32 %14, %13
%16 = sext i32 %15 to i64
%17 = tail call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = tail call i32 (i32, i8*, ...) @diagnostics(i32 0, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %11
%23 = tail call i32 @my_strlcpy(i8* %18, i8* %0, i64 %16)
%24 = tail call i32 @my_strlcat(i8* %18, i8* %1, i64 %16)
br label %25
25: ; preds = %5, %22, %9, %6
%26 = phi i8* [ %7, %6 ], [ %10, %9 ], [ %18, %22 ], [ null, %5 ]
ret i8* %26
}