#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 */
char *malloc_or_die(int, char const *, int);
int safestrlen(char const *);
int /*<<< orphan*/ strcat(char *, char const *);
char *safestrdup2(const char *s1, const char *s2, const char *file, int line) {
  int n = 1 + (s1 ? safestrlen(s1) : 0) + (s2 ? safestrlen(s2) : 0);
  char *s = malloc_or_die(n, file, line);
  s[0] = 0;
  if (s1)
    strcat(s, s1);
  if (s2)
    strcat(s, s2);
  return (s);
}


x86 assembly (clang, -O0):
<safestrdup2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1163 <safestrdup2+0x33>
mov    -0x8(%rbp),%rdi
call   1040 <safestrlen@plt>
mov    %eax,-0x2c(%rbp)
jmp    116d <safestrdup2+0x3d>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    116d <safestrdup2+0x3d>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1192 <safestrdup2+0x62>
mov    -0x10(%rbp),%rdi
call   1040 <safestrlen@plt>
mov    %eax,-0x34(%rbp)
jmp    119c <safestrdup2+0x6c>
xor    %eax,%eax
mov    %eax,-0x34(%rbp)
jmp    119c <safestrdup2+0x6c>
mov    -0x30(%rbp),%eax
mov    -0x34(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <malloc_or_die@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x8(%rbp)
je     11d9 <safestrdup2+0xa9>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcat@plt>
cmpq   $0x0,-0x10(%rbp)
je     11f1 <safestrdup2+0xc1>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safestrdup2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     1167 <safestrdup2+0x37>
mov    %rbx,%rdi
call   1040 <safestrlen@plt>
mov    %eax,%ebp
add    $0x1,%ebp
test   %r14,%r14
je     1171 <safestrdup2+0x41>
mov    %r14,%rdi
call   1040 <safestrlen@plt>
mov    %eax,%edi
jmp    1173 <safestrdup2+0x43>
mov    $0x1,%ebp
test   %r14,%r14
jne    115b <safestrdup2+0x2b>
xor    %edi,%edi
add    %ebp,%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1030 <malloc_or_die@plt>
mov    %rax,%rbp
movb   $0x0,(%rax)
test   %rbx,%rbx
je     1196 <safestrdup2+0x66>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
test   %r14,%r14
je     11a6 <safestrdup2+0x76>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @safestrdup2(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = load i8*, i8** %5
%15 = call i32 @safestrlen(i8* %14)
br label %17
16: ; preds = %4
br label %17
17: ; preds = %16, %13
%18 = phi i32 [ %15, %13 ], [ 0, %16 ]
%19 = add nsw i32 1, %18
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i8*, i8** %6
%24 = call i32 @safestrlen(i8* %23)
br label %26
25: ; preds = %17
br label %26
26: ; preds = %25, %22
%27 = phi i32 [ %24, %22 ], [ 0, %25 ]
%28 = add nsw i32 %19, %27
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = load i8*, i8** %7
%31 = load i32, i32* %8
%32 = call i8* @malloc_or_die(i32 %29, i8* %30, i32 %31)
store i8* %32, i8** %10
%33 = load i8*, i8** %10
%34 = getelementptr inbounds i8, i8* %33, i64 0
store i8 0, i8* %34
%35 = load i8*, i8** %5
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %41
37: ; preds = %26
%38 = load i8*, i8** %10
%39 = load i8*, i8** %5
%40 = call i32 @strcat(i8* %38, i8* %39)
br label %41
41: ; preds = %37, %26
%42 = load i8*, i8** %6
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i8*, i8** %10
%46 = load i8*, i8** %6
%47 = call i32 @strcat(i8* %45, i8* %46)
br label %48
48: ; preds = %44, %41
%49 = load i8*, i8** %10
ret i8* %49
}

LLVM IR (-O2):
define i8* @safestrdup2(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = tail call i32 @safestrlen(i8* %0)
%8 = add i32 %7, 1
br label %9
9: ; preds = %4, %6
%10 = phi i32 [ %8, %6 ], [ 1, %4 ]
%11 = icmp eq i8* %1, null
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @safestrlen(i8* %1)
br label %14
14: ; preds = %9, %12
%15 = phi i32 [ %13, %12 ], [ 0, %9 ]
%16 = add nsw i32 %15, %10
%17 = tail call i8* @malloc_or_die(i32 %16, i8* %2, i32 %3)
store i8 0, i8* %17
br i1 %5, label %20, label %18
18: ; preds = %14
%19 = tail call i32 @strcat(i8* %17, i8* %0)
br label %20
20: ; preds = %18, %14
br i1 %11, label %23, label %21
21: ; preds = %20
%22 = tail call i32 @strcat(i8* %17, i8* %1)
br label %23
23: ; preds = %21, %20
ret i8* %17
}