#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*/ vassert(int /*<<< orphan*/, char *);
char *strcat(char *str1, const char *str2) {
  char *res = str1;
  vassert(str1 != NULL, "str1 == NULL");
  vassert(str2 != NULL, "str2 == NULL");
  while (*str1)
    str1++;
  while (*str2)
    *str1++ = *str2++;
  *str1 = '\0';
  return res;
}


x86 assembly (clang, -O0):
<strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xec4(%rip),%rsi
call   1030 <vassert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xeb8(%rip),%rsi
call   1030 <vassert@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1178 <strcat+0x68>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    115a <strcat+0x4a>
jmp    117d <strcat+0x6d>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b1 <strcat+0xa1>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    117d <strcat+0x6d>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcat>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
lea    0xed6(%rip),%rsi
call   1030 <vassert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
lea    0xece(%rip),%rsi
call   1030 <vassert@plt>
mov    %r14,%rax
nopw   0x0(%rax,%rax,1)
mov    %rax,%rdx
add    $0x1,%rax
cmpb   $0x0,(%rdx)
jne    1150 <strcat+0x40>
mov    (%rbx),%cl
test   %cl,%cl
je     1186 <strcat+0x76>
mov    $0xffffffffffffffff,%rdx
nopl   0x0(%rax)
mov    %cl,(%rax,%rdx,1)
movzbl 0x2(%rbx,%rdx,1),%ecx
add    $0x1,%rdx
test   %cl,%cl
jne    1170 <strcat+0x60>
add    %rdx,%rax
mov    %rax,%rdx
movb   $0x0,(%rdx)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"str1 == NULL\00"
@.str.1 = [13 x i8] c"str2 == NULL\00"
define i8* @strcat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
store i8* %6, i8** %5
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @vassert(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @vassert(i32 %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %19, %2
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %3
br label %15
22: ; preds = %15
br label %23
23: ; preds = %27, %22
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
%30 = load i8, i8* %28
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %3
store i8 %30, i8* %31
br label %23
33: ; preds = %23
%34 = load i8*, i8** %3
store i8 0, i8* %34
%35 = load i8*, i8** %5
ret i8* %35
}

LLVM IR (-O2):
@.str = [13 x i8] c"str1 == NULL\00"
@.str.1 = [13 x i8] c"str2 == NULL\00"
define i8* @strcat(i8* returned %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @vassert(i32 %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = icmp ne i8* %1, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @vassert(i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %9, %2
%10 = phi i8* [ %0, %2 ], [ %13, %9 ]
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
%13 = getelementptr inbounds i8, i8* %10, i64 1
br i1 %12, label %14, label %9
14: ; preds = %9
%15 = load i8, i8* %1
%16 = icmp eq i8 %15, 0
br i1 %16, label %25, label %17
17: ; preds = %14, %17
%18 = phi i8 [ %23, %17 ], [ %15, %14 ]
%19 = phi i8* [ %22, %17 ], [ %10, %14 ]
%20 = phi i8* [ %21, %17 ], [ %1, %14 ]
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = getelementptr inbounds i8, i8* %19, i64 1
store i8 %18, i8* %19
%23 = load i8, i8* %21
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %17
25: ; preds = %17, %14
%26 = phi i8* [ %10, %14 ], [ %22, %17 ]
store i8 0, i8* %26
ret i8* %0
}