#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 strlen_my(char *);
int /*<<< orphan*/ strncpy(char **, char **, int);
int strncat_my(char *dst, char *src, int n) {
  int len_s = 0;
  int len_d = 0;
  len_s = strlen_my(src);
  len_d = strlen_my(dst);
  if (len_d == 0) {
    strncpy(&dst, &src, len_s);
    return 0;
  } else {
    while (*dst++ != '\0') {
    };
    *dst--;
    if (len_s == 0) {
      return 0;
    } else {
      while ((*dst++ = *src++) != '\0') {
      };
    };
  };
}


x86 assembly (clang, -O0):
<strncat_my>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen_my@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen_my@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    117f <strncat_my+0x5f>
mov    -0x20(%rbp),%edx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    1208 <strncat_my+0xe8>
jmp    1184 <strncat_my+0x64>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a4 <strncat_my+0x84>
jmp    1184 <strncat_my+0x64>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11c6 <strncat_my+0xa6>
movl   $0x0,-0x4(%rbp)
jmp    1208 <strncat_my+0xe8>
jmp    11cb <strncat_my+0xab>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0x0,%eax
je     11fe <strncat_my+0xde>
jmp    11cb <strncat_my+0xab>
jmp    1203 <strncat_my+0xe3>
jmp    1208 <strncat_my+0xe8>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strncat_my>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdi,0x8(%rsp)
mov    %rsi,(%rsp)
mov    %rsi,%rdi
call   1040 <strlen_my@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen_my@plt>
test   %eax,%eax
je     11a5 <strncat_my+0x85>
nopl   (%rax)
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    1150 <strncat_my+0x30>
test   %ebp,%ebp
je     11b4 <strncat_my+0x94>
lea    0x1(%r14),%rax
mov    %rax,(%rsp)
mov    (%r14),%al
mov    %rbx,0x8(%rsp)
mov    %al,-0x1(%rbx)
test   %al,%al
je     11b4 <strncat_my+0x94>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rsp),%rax
mov    0x8(%rsp),%rcx
lea    0x1(%rax),%rdx
mov    %rdx,(%rsp)
movzbl (%rax),%eax
lea    0x1(%rcx),%rdx
mov    %rdx,0x8(%rsp)
mov    %al,(%rcx)
test   %al,%al
jne    1180 <strncat_my+0x60>
jmp    11b4 <strncat_my+0x94>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @strncat_my(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = tail call i32 @strlen_my(i8* %1)
%7 = tail call i32 @strlen_my(i8* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = call i32 @strncpy(i8** %4, i8** %5, i32 %6)
br label %30
11: ; preds = %3, %11
%12 = phi i8* [ %13, %11 ], [ %0, %3 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %12
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %11
16: ; preds = %11
%17 = icmp eq i32 %6, 0
br i1 %17, label %30, label %18
18: ; preds = %16
%19 = getelementptr inbounds i8, i8* %1, i64 1
store i8* %19, i8** %5
%20 = load i8, i8* %1
%21 = getelementptr inbounds i8, i8* %12, i64 1
store i8* %21, i8** %4
store i8 %20, i8* %12
%22 = icmp eq i8 %20, 0
br i1 %22, label %30, label %23
23: ; preds = %18, %23
%24 = load i8*, i8** %5
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %24, i64 1
store i8* %26, i8** %5
%27 = load i8, i8* %24
%28 = getelementptr inbounds i8, i8* %25, i64 1
store i8* %28, i8** %4
store i8 %27, i8* %25
%29 = icmp eq i8 %27, 0
br i1 %29, label %30, label %23
30: ; preds = %23, %18, %16, %9
ret i32 0
}