#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*/ perror(char *);
char *str_new(size_t const);
int /*<<< orphan*/ strncat(char *, char const *, size_t const);
int /*<<< orphan*/ strncpy(char *, char const *, size_t const);
char *str_njoin(const char *s1, const char *s2, const size_t n1,
                const size_t n2) {
  char *new_str = str_new(n1 + n2);
  if (new_str != NULL) {
    strncpy(new_str, s1, n1);
    strncat(new_str, s2, n2);
  } else {
    perror("str_njoin: ");
  }
  return (new_str);
}


x86 assembly (clang, -O0):
<str_njoin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    -0x20(%rbp),%rdi
call   1050 <str_new@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     119b <str_njoin+0x5b>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <strncat@plt>
jmp    11a7 <str_njoin+0x67>
lea    0xe5e(%rip),%rdi
call   1060 <perror@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_njoin>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r13
lea    (%rcx,%rdx,1),%rdi
call   1050 <str_new@plt>
mov    %rax,%rbx
test   %rax,%rax
je     118f <str_njoin+0x4f>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <strncat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe6a(%rip),%rdi
call   1060 <perror@plt>
jmp    1182 <str_njoin+0x42>

LLVM IR (-O0):
@.str = [12 x i8] c"str_njoin: \00"
define i8* @str_njoin(i8* %0, i8* %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%10 = load i64, i64* %7
%11 = load i64, i64* %8
%12 = add i64 %10, %11
%13 = call i8* @str_new(i64 %12)
store i8* %13, i8** %9
%14 = load i8*, i8** %9
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %25
16: ; preds = %4
%17 = load i8*, i8** %9
%18 = load i8*, i8** %5
%19 = load i64, i64* %7
%20 = call i32 @strncpy(i8* %17, i8* %18, i64 %19)
%21 = load i8*, i8** %9
%22 = load i8*, i8** %6
%23 = load i64, i64* %8
%24 = call i32 @strncat(i8* %21, i8* %22, i64 %23)
br label %27
25: ; preds = %4
%26 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %16
%28 = load i8*, i8** %9
ret i8* %28
}

LLVM IR (-O2):
@.str = [12 x i8] c"str_njoin: \00"
define i8* @str_njoin(i8* %0, i8* %1, i64 %2, i64 %3) {
%5 = add i64 %3, %2
%6 = tail call i8* @str_new(i64 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = tail call i32 @strncpy(i8* %6, i8* %0, i64 %2)
%10 = tail call i32 @strncat(i8* %6, i8* %1, i64 %3)
br label %13
11: ; preds = %4
%12 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
ret i8* %6
}