#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ hz_assert_str_eq(char *, char *);
char *hz_assert_strncpy_ok(char *, char *, int);
void test_utils_strncpy_concat_loop(void) {
  char buf[100];
  char *dest = buf;
  char *strs[4] = {"Alpha", "Beta", "Charlie", "Delta"};
  for (int i = 0; i < 4; ++i) {
    dest = hz_assert_strncpy_ok(dest, strs[i], sizeof(buf) - (dest - buf));
  }
  hz_assert_str_eq(buf, "AlphaBetaCharlieDelta");
}


x86 assembly (clang, -O0):
<test_utils_strncpy_concat_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    0x2cc6(%rip),%rax
mov    %rax,-0xa0(%rbp)
mov    0x2cc0(%rip),%rax
mov    %rax,-0x98(%rbp)
mov    0x2cba(%rip),%rax
mov    %rax,-0x90(%rbp)
mov    0x2cb4(%rip),%rax
mov    %rax,-0x88(%rbp)
movl   $0x0,-0xa4(%rbp)
cmpl   $0x4,-0xa4(%rbp)
jge    11c7 <test_utils_strncpy_concat_loop+0xa7>
mov    -0x78(%rbp),%rdi
movslq -0xa4(%rbp),%rax
mov    -0xa0(%rbp,%rax,8),%rsi
ff
mov    -0x78(%rbp),%rcx
lea    -0x70(%rbp),%rax
sub    %rax,%rcx
mov    $0x64,%eax
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <hz_assert_strncpy_ok@plt>
mov    %rax,-0x78(%rbp)
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
jmp    1175 <test_utils_strncpy_concat_loop+0x55>
lea    -0x70(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1030 <hz_assert_str_eq@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_utils_strncpy_concat_loop>:
push   %rbx
sub    $0x70,%rsp
lea    0xed4(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%edx
call   1040 <hz_assert_strncpy_ok@plt>
mov    %ebx,%edx
sub    %eax,%edx
add    $0x64,%edx
lea    0xebc(%rip),%rsi
mov    %rax,%rdi
call   1040 <hz_assert_strncpy_ok@plt>
mov    %ebx,%edx
sub    %eax,%edx
add    $0x64,%edx
lea    0xeab(%rip),%rsi
mov    %rax,%rdi
call   1040 <hz_assert_strncpy_ok@plt>
mov    %ebx,%edx
sub    %eax,%edx
add    $0x64,%edx
lea    0xead(%rip),%rsi
mov    %rax,%rdi
call   1040 <hz_assert_strncpy_ok@plt>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <hz_assert_str_eq@plt>
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Alpha\00"
@.str.1 = [5 x i8] c"Beta\00"
@.str.2 = [8 x i8] c"Charlie\00"
@.str.3 = [6 x i8] c"Delta\00"
@__const.test_utils_strncpy_concat_loop.strs = [4 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0)]
@.str.4 = [22 x i8] c"AlphaBetaCharlieDelta\00"
define void @test_utils_strncpy_concat_loop() {
%1 = alloca [100 x i8]
%2 = alloca i8*
%3 = alloca [4 x i8*]
%4 = alloca i32
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
store i8* %5, i8** %2
%6 = bitcast [4 x i8*]* %3 to i8*
store i32 0, i32* %4
br label %7
7: ; preds = %24, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %27
10: ; preds = %7
%11 = load i8*, i8** %2
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 %13
%15 = load i8*, i8** %14
%16 = load i8*, i8** %2
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = sub i64 100, %20
%22 = trunc i64 %21 to i32
%23 = call i8* @hz_assert_strncpy_ok(i8* %11, i8* %15, i32 %22)
store i8* %23, i8** %2
br label %24
24: ; preds = %10
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %7
27: ; preds = %7
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%29 = call i32 @hz_assert_str_eq(i8* %28, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"Alpha\00"
@.str.1 = [5 x i8] c"Beta\00"
@.str.2 = [8 x i8] c"Charlie\00"
@.str.3 = [6 x i8] c"Delta\00"
@.str.4 = [22 x i8] c"AlphaBetaCharlieDelta\00"
define void @test_utils_strncpy_concat_loop() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = ptrtoint [100 x i8]* %1 to i64
%4 = call i8* @hz_assert_strncpy_ok(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 100)
%5 = ptrtoint i8* %4 to i64
%6 = sub i64 %3, %5
%7 = trunc i64 %6 to i32
%8 = add i32 %7, 100
%9 = call i8* @hz_assert_strncpy_ok(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = ptrtoint i8* %9 to i64
%11 = sub i64 %3, %10
%12 = trunc i64 %11 to i32
%13 = add i32 %12, 100
%14 = call i8* @hz_assert_strncpy_ok(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = ptrtoint i8* %14 to i64
%16 = sub i64 %3, %15
%17 = trunc i64 %16 to i32
%18 = add i32 %17, 100
%19 = call i8* @hz_assert_strncpy_ok(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = call i32 @hz_assert_str_eq(i8* %2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
ret void
}