#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 int /*<<< orphan*/ mydest;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, int, char *);
char *strnbld(char *, char *, int);
char *strncat(char *, char *, int);
int main(int argc, char *argv[]) {
  int i;
  char mydest[20];
  char *ret;
  int n;
  char *strings[] = {"Say", " ", "hello", " ", "world"};
  int numstrings = 5;
  for (n = 2; n <= 6; n++) {
    memset(mydest, '#', sizeof(mydest));
    mydest[sizeof(mydest) - 1] = '\0';
    for (i = 0; i < numstrings; i++) {
      if (i == 0) {
        ret = strnbld(mydest, strings[i], n);
      } else {
        ret = strnbld(ret, strings[i], n);
      }
    }
    printf("test_strnbld - using strnbld (%d): Final string = [%s]\n", n,
           mydest);
    memset(mydest, '#', sizeof(mydest));
    mydest[sizeof(mydest) - 1] = '\0';
    for (i = numstrings - 1; i >= 0; i--) {
      if (i == numstrings - 1) {
        ret = strnbld(mydest, strings[i], n);
      } else {
        ret = strnbld(ret, strings[i], n);
      }
    }
    printf("test_strnbld - using strnbld (%d): Final string = [%s]\n", n,
           mydest);
  }
  for (n = 2; n <= 6; n++) {
    memset(mydest, '#', sizeof(mydest));
    mydest[0] = '\0';
    mydest[sizeof(mydest) - 1] = '\0';
    for (i = 0; i < numstrings; i++) {
      if (i == 0) {
        ret = strncat(mydest, strings[i], n);
      } else {
        ret = strncat(mydest, strings[i], n);
      }
    }
    printf("test_strnbld - using strncat (%d) for comparison: Final string = "
           "[%s]\n",
           n, mydest);
    memset(mydest, '#', sizeof(mydest));
    mydest[0] = '\0';
    mydest[sizeof(mydest) - 1] = '\0';
    for (i = numstrings - 1; i >= 0; i--) {
      if (i == numstrings - 1) {
        ret = strncat(mydest, strings[i], n);
      } else {
        ret = strncat(mydest, strings[i], n);
      }
    }
    printf("test_strnbld - using strncat (%d) for comparison: Final string = "
           "[%s]\n",
           n, mydest);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    0xe90(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    0xe89(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    0xe80(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xe73(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xe70(%rip),%rax
mov    %rax,-0x50(%rbp)
movl   $0x5,-0x74(%rbp)
movl   $0x2,-0x3c(%rbp)
cmpl   $0x6,-0x3c(%rbp)
jg     12ef <main+0x1af>
lea    -0x30(%rbp),%rdi
mov    $0x23,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
movb   $0x0,-0x1d(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x74(%rbp),%eax
jge    1236 <main+0xf6>
cmpl   $0x0,-0x14(%rbp)
jne    120a <main+0xca>
lea    -0x30(%rbp),%rdi
movslq -0x14(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
mov    -0x3c(%rbp),%edx
call   1060 <strnbld@plt>
mov    %rax,-0x38(%rbp)
jmp    1223 <main+0xe3>
mov    -0x38(%rbp),%rdi
movslq -0x14(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
mov    -0x3c(%rbp),%edx
call   1060 <strnbld@plt>
mov    %rax,-0x38(%rbp)
jmp    1228 <main+0xe8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d6 <main+0x96>
mov    -0x3c(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    0xdce(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x23,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
movb   $0x0,-0x1d(%rbp)
mov    -0x74(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     12ce <main+0x18e>
mov    -0x14(%rbp),%eax
mov    -0x74(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    12a2 <main+0x162>
lea    -0x30(%rbp),%rdi
movslq -0x14(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
mov    -0x3c(%rbp),%edx
call   1060 <strnbld@plt>
mov    %rax,-0x38(%rbp)
jmp    12bb <main+0x17b>
mov    -0x38(%rbp),%rdi
movslq -0x14(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
mov    -0x3c(%rbp),%edx
call   1060 <strnbld@plt>
mov    %rax,-0x38(%rbp)
jmp    12c0 <main+0x180>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1269 <main+0x129>
mov    -0x3c(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    0xd36(%rip),%rdi
call   1030 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11ae <main+0x6e>
movl   $0x2,-0x3c(%rbp)
cmpl   $0x6,-0x3c(%rbp)
jg     143f <main+0x2ff>
lea    -0x30(%rbp),%rdi
mov    $0x23,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
movb   $0x0,-0x30(%rbp)
movb   $0x0,-0x1d(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x74(%rbp),%eax
jge    1382 <main+0x242>
cmpl   $0x0,-0x14(%rbp)
jne    1356 <main+0x216>
lea    -0x30(%rbp),%rdi
movslq -0x14(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
mov    -0x3c(%rbp),%edx
call   1050 <strncat@plt>
mov    %rax,-0x38(%rbp)
jmp    136f <main+0x22f>
lea    -0x30(%rbp),%rdi
movslq -0x14(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
mov    -0x3c(%rbp),%edx
call   1050 <strncat@plt>
mov    %rax,-0x38(%rbp)
jmp    1374 <main+0x234>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1322 <main+0x1e2>
mov    -0x3c(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    0xcba(%rip),%rdi
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x23,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
movb   $0x0,-0x30(%rbp)
movb   $0x0,-0x1d(%rbp)
mov    -0x74(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     141e <main+0x2de>
mov    -0x14(%rbp),%eax
mov    -0x74(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    13f2 <main+0x2b2>
lea    -0x30(%rbp),%rdi
movslq -0x14(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
mov    -0x3c(%rbp),%edx
call   1050 <strncat@plt>
mov    %rax,-0x38(%rbp)
jmp    140b <main+0x2cb>
lea    -0x30(%rbp),%rdi
movslq -0x14(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
mov    -0x3c(%rbp),%edx
call   1050 <strncat@plt>
mov    %rax,-0x38(%rbp)
jmp    1410 <main+0x2d0>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    13b9 <main+0x279>
mov    -0x3c(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    0xc1e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12f6 <main+0x1b6>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x2,%ebx
mov    %rsp,%r14
lea    0xea7(%rip),%r12
nopl   (%rax)
mov    %r14,%rdi
mov    $0x23,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
movb   $0x0,0x13(%rsp)
mov    %r14,%rdi
lea    0xe7f(%rip),%rsi
mov    %ebx,%edx
call   1060 <strnbld@plt>
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1060 <strnbld@plt>
mov    %rax,%rdi
lea    0xe67(%rip),%rbp
mov    %rbp,%rsi
mov    %ebx,%edx
call   1060 <strnbld@plt>
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1060 <strnbld@plt>
mov    %rax,%rdi
lea    0xe4c(%rip),%r15
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <strnbld@plt>
lea    0xe41(%rip),%r13
mov    %r13,%rdi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x23,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
movb   $0x0,0x13(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <strnbld@plt>
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1060 <strnbld@plt>
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1060 <strnbld@plt>
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1060 <strnbld@plt>
mov    %rax,%rdi
lea    0xdcd(%rip),%rsi
mov    %ebx,%edx
call   1060 <strnbld@plt>
mov    %r13,%rdi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    $0x7,%ebx
jne    1160 <main+0x20>
mov    $0x2,%ebx
mov    %rsp,%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x23,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
movb   $0x0,(%rsp)
movb   $0x0,0x13(%rsp)
mov    %rbp,%rdi
lea    0xd7b(%rip),%rsi
mov    %ebx,%edx
call   1050 <strncat@plt>
mov    %rbp,%rdi
lea    0xd6e(%rip),%r12
mov    %r12,%rsi
mov    %ebx,%edx
call   1050 <strncat@plt>
mov    %rbp,%rdi
lea    0xd5c(%rip),%r13
mov    %r13,%rsi
mov    %ebx,%edx
call   1050 <strncat@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1050 <strncat@plt>
mov    %rbp,%rdi
lea    0xd41(%rip),%r14
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <strncat@plt>
lea    0xd6e(%rip),%r15
mov    %r15,%rdi
mov    %ebx,%esi
mov    %rbp,%rdx
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    $0x23,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
movb   $0x0,(%rsp)
movb   $0x0,0x13(%rsp)
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <strncat@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1050 <strncat@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1050 <strncat@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1050 <strncat@plt>
mov    %rbp,%rdi
lea    0xcbe(%rip),%rsi
mov    %ebx,%edx
call   1050 <strncat@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %rbp,%rdx
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    $0x7,%ebx
jne    1260 <main+0x120>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"Say\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [6 x i8] c"hello\00"
@.str.3 = [6 x i8] c"world\00"
@.str.4 = [56 x i8] c"test_strnbld - using strnbld (%d): Final string = [%s]\0A\00"
@.str.5 = [71 x i8] c"test_strnbld - using strncat (%d) for comparison: Final string = [%s]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [20 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [5 x i8*]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [5 x i8*]* %10 to i8*
%13 = bitcast i8* %12 to [5 x i8*]*
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %13, i32 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8** %14
%15 = getelementptr inbounds [5 x i8*], [5 x i8*]* %13, i32 0, i32 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8** %15
%16 = getelementptr inbounds [5 x i8*], [5 x i8*]* %13, i32 0, i32 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8** %16
%17 = getelementptr inbounds [5 x i8*], [5 x i8*]* %13, i32 0, i32 3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8** %17
%18 = getelementptr inbounds [5 x i8*], [5 x i8*]* %13, i32 0, i32 4
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0), i8** %18
store i32 5, i32* %11
store i32 2, i32* %9
br label %19
19: ; preds = %94, %2
%20 = load i32, i32* %9
%21 = icmp sle i32 %20, 6
br i1 %21, label %22, label %97
22: ; preds = %19
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%24 = call i32 @memset(i8* %23, i8 signext 35, i32 20)
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 19
store i8 0, i8* %25
store i32 0, i32* %6
br label %26
26: ; preds = %50, %22
%27 = load i32, i32* %6
%28 = load i32, i32* %11
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %53
30: ; preds = %26
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [5 x i8*], [5 x i8*]* %10, i64 0, i64 %36
%38 = load i8*, i8** %37
%39 = load i32, i32* %9
%40 = call i8* @strnbld(i8* %34, i8* %38, i32 %39)
store i8* %40, i8** %8
br label %49
41: ; preds = %30
%42 = load i8*, i8** %8
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [5 x i8*], [5 x i8*]* %10, i64 0, i64 %44
%46 = load i8*, i8** %45
%47 = load i32, i32* %9
%48 = call i8* @strnbld(i8* %42, i8* %46, i32 %47)
store i8* %48, i8** %8
br label %49
49: ; preds = %41, %33
br label %50
50: ; preds = %49
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %26
53: ; preds = %26
%54 = load i32, i32* %9
%55 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%56 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 %54, i8* %55)
%57 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%58 = call i32 @memset(i8* %57, i8 signext 35, i32 20)
%59 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 19
store i8 0, i8* %59
%60 = load i32, i32* %11
%61 = sub nsw i32 %60, 1
store i32 %61, i32* %6
br label %62
62: ; preds = %87, %53
%63 = load i32, i32* %6
%64 = icmp sge i32 %63, 0
br i1 %64, label %65, label %90
65: ; preds = %62
%66 = load i32, i32* %6
%67 = load i32, i32* %11
%68 = sub nsw i32 %67, 1
%69 = icmp eq i32 %66, %68
br i1 %69, label %70, label %78
70: ; preds = %65
%71 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%72 = load i32, i32* %6
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [5 x i8*], [5 x i8*]* %10, i64 0, i64 %73
%75 = load i8*, i8** %74
%76 = load i32, i32* %9
%77 = call i8* @strnbld(i8* %71, i8* %75, i32 %76)
store i8* %77, i8** %8
br label %86
78: ; preds = %65
%79 = load i8*, i8** %8
%80 = load i32, i32* %6
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [5 x i8*], [5 x i8*]* %10, i64 0, i64 %81
%83 = load i8*, i8** %82
%84 = load i32, i32* %9
%85 = call i8* @strnbld(i8* %79, i8* %83, i32 %84)
store i8* %85, i8** %8
br label %86
86: ; preds = %78, %70
br label %87
87: ; preds = %86
%88 = load i32, i32* %6
%89 = add nsw i32 %88, -1
store i32 %89, i32* %6
br label %62
90: ; preds = %62
%91 = load i32, i32* %9
%92 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%93 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 %91, i8* %92)
br label %94
94: ; preds = %90
%95 = load i32, i32* %9
%96 = add nsw i32 %95, 1
store i32 %96, i32* %9
br label %19
97: ; preds = %19
store i32 2, i32* %9
br label %98
98: ; preds = %175, %97
%99 = load i32, i32* %9
%100 = icmp sle i32 %99, 6
br i1 %100, label %101, label %178
101: ; preds = %98
%102 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%103 = call i32 @memset(i8* %102, i8 signext 35, i32 20)
%104 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
store i8 0, i8* %104
%105 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 19
store i8 0, i8* %105
store i32 0, i32* %6
br label %106
106: ; preds = %130, %101
%107 = load i32, i32* %6
%108 = load i32, i32* %11
%109 = icmp slt i32 %107, %108
br i1 %109, label %110, label %133
110: ; preds = %106
%111 = load i32, i32* %6
%112 = icmp eq i32 %111, 0
br i1 %112, label %113, label %121
113: ; preds = %110
%114 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%115 = load i32, i32* %6
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds [5 x i8*], [5 x i8*]* %10, i64 0, i64 %116
%118 = load i8*, i8** %117
%119 = load i32, i32* %9
%120 = call i8* @strncat(i8* %114, i8* %118, i32 %119)
store i8* %120, i8** %8
br label %129
121: ; preds = %110
%122 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%123 = load i32, i32* %6
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds [5 x i8*], [5 x i8*]* %10, i64 0, i64 %124
%126 = load i8*, i8** %125
%127 = load i32, i32* %9
%128 = call i8* @strncat(i8* %122, i8* %126, i32 %127)
store i8* %128, i8** %8
br label %129
129: ; preds = %121, %113
br label %130
130: ; preds = %129
%131 = load i32, i32* %6
%132 = add nsw i32 %131, 1
store i32 %132, i32* %6
br label %106
133: ; preds = %106
%134 = load i32, i32* %9
%135 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%136 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.5, i64 0, i64 0), i32 %134, i8* %135)
%137 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%138 = call i32 @memset(i8* %137, i8 signext 35, i32 20)
%139 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
store i8 0, i8* %139
%140 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 19
store i8 0, i8* %140
%141 = load i32, i32* %11
%142 = sub nsw i32 %141, 1
store i32 %142, i32* %6
br label %143
143: ; preds = %168, %133
%144 = load i32, i32* %6
%145 = icmp sge i32 %144, 0
br i1 %145, label %146, label %171
146: ; preds = %143
%147 = load i32, i32* %6
%148 = load i32, i32* %11
%149 = sub nsw i32 %148, 1
%150 = icmp eq i32 %147, %149
br i1 %150, label %151, label %159
151: ; preds = %146
%152 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%153 = load i32, i32* %6
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds [5 x i8*], [5 x i8*]* %10, i64 0, i64 %154
%156 = load i8*, i8** %155
%157 = load i32, i32* %9
%158 = call i8* @strncat(i8* %152, i8* %156, i32 %157)
store i8* %158, i8** %8
br label %167
159: ; preds = %146
%160 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%161 = load i32, i32* %6
%162 = sext i32 %161 to i64
%163 = getelementptr inbounds [5 x i8*], [5 x i8*]* %10, i64 0, i64 %162
%164 = load i8*, i8** %163
%165 = load i32, i32* %9
%166 = call i8* @strncat(i8* %160, i8* %164, i32 %165)
store i8* %166, i8** %8
br label %167
167: ; preds = %159, %151
br label %168
168: ; preds = %167
%169 = load i32, i32* %6
%170 = add nsw i32 %169, -1
store i32 %170, i32* %6
br label %143
171: ; preds = %143
%172 = load i32, i32* %9
%173 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%174 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.5, i64 0, i64 0), i32 %172, i8* %173)
br label %175
175: ; preds = %171
%176 = load i32, i32* %9
%177 = add nsw i32 %176, 1
store i32 %177, i32* %9
br label %98
178: ; preds = %98
%179 = load i32, i32* %3
ret i32 %179
}

LLVM IR (-O2):
@.str = [4 x i8] c"Say\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [6 x i8] c"hello\00"
@.str.3 = [6 x i8] c"world\00"
@.str.4 = [56 x i8] c"test_strnbld - using strnbld (%d): Final string = [%s]\0A\00"
@.str.5 = [71 x i8] c"test_strnbld - using strncat (%d) for comparison: Final string = [%s]\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 19
br label %6
6: ; preds = %2, %6
%7 = phi i32 [ 2, %2 ], [ %22, %6 ]
%8 = call i32 @memset(i8* %4, i8 signext 35, i32 20)
store i8 0, i8* %5
%9 = call i8* @strnbld(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
%10 = call i8* @strnbld(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%11 = call i8* @strnbld(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%12 = call i8* @strnbld(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%13 = call i8* @strnbld(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %7)
%14 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 %7, i8* %4)
%15 = call i32 @memset(i8* %4, i8 signext 35, i32 20)
store i8 0, i8* %5
%16 = call i8* @strnbld(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %7)
%17 = call i8* @strnbld(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%18 = call i8* @strnbld(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%19 = call i8* @strnbld(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%20 = call i8* @strnbld(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
%21 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 %7, i8* %4)
%22 = add nuw nsw i32 %7, 1
%23 = icmp eq i32 %22, 7
br i1 %23, label %24, label %6
24: ; preds = %6, %24
%25 = phi i32 [ %40, %24 ], [ 2, %6 ]
%26 = call i32 @memset(i8* %4, i8 signext 35, i32 20)
store i8 0, i8* %4
store i8 0, i8* %5
%27 = call i8* @strncat(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %25)
%28 = call i8* @strncat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%29 = call i8* @strncat(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%30 = call i8* @strncat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%31 = call i8* @strncat(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%32 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.5, i64 0, i64 0), i32 %25, i8* %4)
%33 = call i32 @memset(i8* %4, i8 signext 35, i32 20)
store i8 0, i8* %4
store i8 0, i8* %5
%34 = call i8* @strncat(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%35 = call i8* @strncat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%36 = call i8* @strncat(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%37 = call i8* @strncat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%38 = call i8* @strncat(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %25)
%39 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.5, i64 0, i64 0), i32 %25, i8* %4)
%40 = add nuw nsw i32 %25, 1
%41 = icmp eq i32 %40, 7
br i1 %41, label %42, label %24
42: ; preds = %24
ret i32 0
}