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


x86 assembly (clang, -O0):
<strncat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xec0(%rip),%rsi
call   1030 <vassert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xeb4(%rip),%rsi
call   1030 <vassert@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     117c <strncat+0x6c>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    115e <strncat+0x4e>
jmp    1181 <strncat+0x71>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     11af <strncat+0x9f>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
seta   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11bf <strncat+0xaf>
jmp    11e6 <strncat+0xd6>
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    1181 <strncat+0x71>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strncat>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
lea    0xed2(%rip),%rsi
call   1030 <vassert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
lea    0xeca(%rip),%rsi
call   1030 <vassert@plt>
mov    %r14,%rax
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdx
add    $0x1,%rax
cmpb   $0x0,(%rdx)
jne    1150 <strncat+0x40>
mov    (%rbx),%cl
test   %cl,%cl
je     11a2 <strncat+0x92>
test   %r15,%r15
je     11a2 <strncat+0x92>
mov    $0x1,%edx
sub    %r15,%rdx
mov    $0xffffffffffffffff,%rsi
cs nopw 0x0(%rax,%rax,1)
mov    %cl,(%rax,%rsi,1)
movzbl 0x2(%rbx,%rsi,1),%ecx
lea    0x1(%rsi),%rdi
test   %cl,%cl
je     119c <strncat+0x8c>
add    %rdx,%rsi
cmp    $0xffffffffffffffff,%rsi
mov    %rdi,%rsi
jne    1180 <strncat+0x70>
add    %rdi,%rax
mov    %rax,%rdx
movb   $0x0,(%rdx)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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