#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 */
typedef char u_int32_t;

/* Variables and functions */
scalar_t__ memcpy(char *, char const *, size_t);
size_t u8_strlen(char *);
u_int32_t *u8_strncat(u_int32_t *dest, const u_int32_t *src, size_t n) {
  int future_length = u8_strlen(dest) + n;
  if (NULL ==
      (u_int32_t *)memcpy(&dest[u8_strlen(dest)], src, n * sizeof(u_int32_t))) {
    return NULL;
  }
  dest[future_length] = '\0';
  return dest;
}


x86 assembly (clang, -O0):
<u8_strncat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <u8_strlen@plt>
add    -0x20(%rbp),%rax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <u8_strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
shl    $0x0,%rdx
call   1040 <memcpy@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1188 <u8_strncat+0x68>
movq   $0x0,-0x8(%rbp)
jmp    119c <u8_strncat+0x7c>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u8_strncat>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
call   1030 <u8_strlen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <u8_strlen@plt>
lea    (%rax,%rbx,1),%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1040 <memcpy@plt>
test   %rax,%rax
je     1161 <u8_strncat+0x41>
add    %r14d,%r15d
movslq %r15d,%rax
movb   $0x0,(%rbx,%rax,1)
jmp    1163 <u8_strncat+0x43>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @u8_strncat(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i8*, i8** %5
%10 = call i64 @u8_strlen(i8* %9)
%11 = load i64, i64* %7
%12 = add i64 %10, %11
%13 = trunc i64 %12 to i32
store i32 %13, i32* %8
%14 = load i8*, i8** %5
%15 = load i8*, i8** %5
%16 = call i64 @u8_strlen(i8* %15)
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8*, i8** %6
%19 = load i64, i64* %7
%20 = mul i64 %19, 1
%21 = call i64 @memcpy(i8* %17, i8* %18, i64 %20)
%22 = inttoptr i64 %21 to i8*
%23 = icmp eq i8* null, %22
br i1 %23, label %24, label %25
24: ; preds = %3
store i8* null, i8** %4
br label %31
25: ; preds = %3
%26 = load i8*, i8** %5
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 0, i8* %29
%30 = load i8*, i8** %5
store i8* %30, i8** %4
br label %31
31: ; preds = %25, %24
%32 = load i8*, i8** %4
ret i8* %32
}

LLVM IR (-O2):
define i8* @u8_strncat(i8* %0, i8* %1, i64 %2) {
%4 = tail call i64 @u8_strlen(i8* %0)
%5 = tail call i64 @u8_strlen(i8* %0)
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = tail call i64 @memcpy(i8* %6, i8* %1, i64 %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %3
%10 = add i64 %4, %2
%11 = shl i64 %10, 32
%12 = ashr exact i64 %11, 32
%13 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 0, i8* %13
br label %14
14: ; preds = %3, %9
%15 = phi i8* [ %0, %9 ], [ null, %3 ]
ret i8* %15
}