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


x86 assembly (clang, -O0):
<safeextend2>:
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 <safeextend2+0x33>
mov    -0x8(%rbp),%rdi
call   1030 <safestrlen@plt>
mov    %eax,-0x30(%rbp)
jmp    116d <safeextend2+0x3d>
xor    %eax,%eax
mov    %eax,-0x30(%rbp)
jmp    116d <safeextend2+0x3d>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1192 <safeextend2+0x62>
mov    -0x10(%rbp),%rdi
call   1030 <safestrlen@plt>
mov    %eax,-0x38(%rbp)
jmp    119c <safeextend2+0x6c>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
jmp    119c <safeextend2+0x6c>
mov    -0x34(%rbp),%eax
mov    -0x38(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <realloc_or_die@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11d0 <safeextend2+0xa0>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     11e8 <safeextend2+0xb8>
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):
<safeextend2>:
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 <safeextend2+0x37>
mov    %rbx,%rdi
call   1030 <safestrlen@plt>
mov    %eax,%ebp
add    $0x1,%ebp
test   %r14,%r14
je     1171 <safeextend2+0x41>
mov    %r14,%rdi
call   1030 <safestrlen@plt>
mov    %eax,%esi
jmp    1173 <safeextend2+0x43>
mov    $0x1,%ebp
test   %r14,%r14
jne    115b <safeextend2+0x2b>
xor    %esi,%esi
add    %ebp,%esi
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r15d,%ecx
call   1040 <realloc_or_die@plt>
mov    %rax,%rbp
test   %rbx,%rbx
je     11a7 <safeextend2+0x77>
test   %r14,%r14
je     119b <safeextend2+0x6b>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
movb   $0x0,0x0(%rbp)
test   %r14,%r14
jne    1190 <safeextend2+0x60>
jmp    119b <safeextend2+0x6b>

LLVM IR (-O0):
define i8* @safeextend2(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
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* %10
%29 = load i8*, i8** %5
%30 = load i32, i32* %10
%31 = load i8*, i8** %7
%32 = load i32, i32* %8
%33 = call i8* @realloc_or_die(i8* %29, i32 %30, i8* %31, i32 %32)
store i8* %33, i8** %9
%34 = load i8*, i8** %5
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %38
36: ; preds = %26
%37 = load i8*, i8** %9
store i8 0, i8* %37
br label %38
38: ; preds = %36, %26
%39 = load i8*, i8** %6
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i8*, i8** %9
%43 = load i8*, i8** %6
%44 = call i32 @strcat(i8* %42, i8* %43)
br label %45
45: ; preds = %41, %38
%46 = load i8*, i8** %9
ret i8* %46
}

LLVM IR (-O2):
define i8* @safeextend2(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* @realloc_or_die(i8* %0, i32 %16, i8* %2, i32 %3)
br i1 %5, label %18, label %19
18: ; preds = %14
store i8 0, i8* %17
br label %19
19: ; preds = %18, %14
br i1 %11, label %22, label %20
20: ; preds = %19
%21 = tail call i32 @strcat(i8* %17, i8* %1)
br label %22
22: ; preds = %20, %19
ret i8* %17
}