#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*/ uint8_t;
typedef int ssize_t;
typedef int int32_t;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ arr_i;
typedef int /*<<< orphan*/ arr_c;

/* Variables and functions */
scalar_t__ memcmp(int /*<<< orphan*/ *, ...);
int /*<<< orphan*/ printf(char *);
int struct_pack(int /*<<< orphan*/ *, int, char *, int, int, int, int, int,
                char, char, char, char, char, char);
void test_struct_pack_repeat(void) {
  uint8_t buf[100];
  ssize_t size;
  int32_t arr_i[5] = {2013, 3, 21, 0, 34};
  char arr_c[6] = "struct";
  size = struct_pack(buf, sizeof(buf), "5i 6c", arr_i[0], arr_i[1], arr_i[2],
                     arr_i[3], arr_i[4], arr_c[0], arr_c[1], arr_c[2], arr_c[3],
                     arr_c[4], arr_c[5]);
  printf("Pack repeated values test: ");
  if (size == sizeof(arr_i) + sizeof(arr_c) &&
      memcmp(&buf[0], arr_i, sizeof(arr_i)) == 0 &&
      memcmp(&buf[sizeof(arr_i)], arr_c, sizeof(arr_c)) == 0)
    printf("PASS\n");
  else
    printf("FAIL\n");
}


x86 assembly (clang, -O0):
<test_struct_pack_repeat>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    0xeb7(%rip),%rax
mov    %rax,-0x1d0(%rbp)
mov    0xeb1(%rip),%rax
mov    %rax,-0x1c8(%rbp)
mov    0xeac(%rip),%eax
mov    %eax,-0x1c0(%rbp)
mov    0xea4(%rip),%eax
mov    %eax,-0x1d6(%rbp)
mov    0xe9b(%rip),%ax
mov    %ax,-0x1d2(%rbp)
lea    -0x1b0(%rbp),%rdi
mov    -0x1d0(%rbp),%ecx
mov    -0x1cc(%rbp),%r8d
mov    -0x1c8(%rbp),%r9d
mov    -0x1c4(%rbp),%r12d
mov    -0x1c0(%rbp),%r15d
mov    -0x1d6(%rbp),%r14b
mov    -0x1d5(%rbp),%bl
mov    -0x1d4(%rbp),%r11b
mov    -0x1d3(%rbp),%r10b
mov    -0x1d2(%rbp),%al
mov    $0x190,%esi
lea    0xe40(%rip),%rdx
mov    %r12d,(%rsp)
mov    %r15d,0x8(%rsp)
movsbl %r14b,%r14d
mov    %r14d,0x10(%rsp)
movsbl %bl,%ebx
mov    %ebx,0x18(%rsp)
movsbl %r11b,%r11d
mov    %r11d,0x20(%rsp)
movsbl %r10b,%r10d
mov    %r10d,0x28(%rsp)
movsbl %al,%eax
mov    %eax,0x30(%rsp)
movsbl -0x1d1(%rbp),%eax
mov    %eax,0x38(%rsp)
call   1050 <struct_pack@plt>
mov    %eax,-0x1b4(%rbp)
lea    0xdf7(%rip),%rdi
call   1030 <printf@plt>
movslq -0x1b4(%rbp),%rax
cmp    $0x1a,%rax
jne    129c <test_struct_pack_repeat+0x16c>
lea    -0x1b0(%rbp),%rdi
lea    -0x1d0(%rbp),%rsi
xor    %eax,%eax
mov    $0x14,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    129c <test_struct_pack_repeat+0x16c>
lea    -0x1b0(%rbp),%rdi
add    $0x50,%rdi
lea    -0x1d6(%rbp),%rsi
xor    %eax,%eax
mov    $0x6,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    129c <test_struct_pack_repeat+0x16c>
lea    0xdaa(%rip),%rdi
call   1030 <printf@plt>
jmp    12a8 <test_struct_pack_repeat+0x178>
lea    0xd9f(%rip),%rdi
call   1030 <printf@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_struct_pack_repeat>:
push   %rbx
sub    $0x1c0,%rsp
mov    0xec2(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xea7(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movw   $0x7463,0xc(%rsp)
movl   $0x75727473,0x8(%rsp)
75
lea    0xea6(%rip),%rdx
lea    0x30(%rsp),%rdi
mov    $0x190,%esi
mov    $0x7dd,%ecx
mov    $0x3,%r8d
mov    $0x15,%r9d
push   $0x74
push   $0x63
push   $0x75
push   $0x72
push   $0x74
push   $0x73
push   $0x22
push   $0x0
call   1060 <struct_pack@plt>
add    $0x40,%rsp
mov    %eax,%ebx
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
cmp    $0x1a,%ebx
jne    11f4 <test_struct_pack_repeat+0xb4>
lea    0x30(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x14,%edx
xor    %eax,%eax
call   1050 <memcmp@plt>
test   %rax,%rax
jne    11f4 <test_struct_pack_repeat+0xb4>
lea    0x80(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x6,%edx
xor    %eax,%eax
call   1050 <memcmp@plt>
test   %rax,%rax
je     1209 <test_struct_pack_repeat+0xc9>
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
add    $0x1c0,%rsp
pop    %rbx
ret
lea    0xe31(%rip),%rdi
jmp    11fb <test_struct_pack_repeat+0xbb>

LLVM IR (-O0):
@__const.test_struct_pack_repeat.arr_i = [5 x i32] [i32 2013, i32 3, i32 21, i32 0, i32 34]
@__const.test_struct_pack_repeat.arr_c = [6 x i8] c"struct"
@.str = [6 x i8] c"5i 6c\00"
@.str.1 = [28 x i8] c"Pack repeated values test: \00"
@.str.2 = [6 x i8] c"PASS\0A\00"
@.str.3 = [6 x i8] c"FAIL\0A\00"
define void @test_struct_pack_repeat() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = alloca [5 x i32]
%4 = alloca [6 x i8]
%5 = bitcast [5 x i32]* %3 to i8*
%6 = bitcast [6 x i8]* %4 to i8*
%7 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%8 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%9 = load i32, i32* %8
%10 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 2
%13 = load i32, i32* %12
%14 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 3
%15 = load i32, i32* %14
%16 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 4
%17 = load i32, i32* %16
%18 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%19 = load i8, i8* %18
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 1
%21 = load i8, i8* %20
%22 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 2
%23 = load i8, i8* %22
%24 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 3
%25 = load i8, i8* %24
%26 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 4
%27 = load i8, i8* %26
%28 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 5
%29 = load i8, i8* %28
%30 = call i32 @struct_pack(i32* %7, i32 400, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %11, i32 %13, i32 %15, i32 %17, i8 signext %19, i8 signext %21, i8 signext %23, i8 signext %25, i8 signext %27, i8 signext %29)
store i32 %30, i32* %2
%31 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* %2
%33 = sext i32 %32 to i64
%34 = icmp eq i64 %33, 26
br i1 %34, label %35, label %47
35: ; preds = %0
%36 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%37 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%38 = call i64 (i32*, ...) @memcmp(i32* %36, i32* %37, i64 20)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %35
%41 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 20
%42 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%43 = call i64 (i32*, ...) @memcmp(i32* %41, i8* %42, i64 6)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %40
%46 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %49
47: ; preds = %40, %35, %0
%48 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %45
ret void
}

LLVM IR (-O2):
@__const.test_struct_pack_repeat.arr_i = [5 x i32] [i32 2013, i32 3, i32 21, i32 0, i32 34]
@__const.test_struct_pack_repeat.arr_c = [6 x i8] c"struct"
@.str = [6 x i8] c"5i 6c\00"
@.str.1 = [28 x i8] c"Pack repeated values test: \00"
@str = [5 x i8] c"FAIL\00"
@str.4 = [5 x i8] c"PASS\00"
define void @test_struct_pack_repeat() {
%1 = alloca [100 x i32]
%2 = alloca [5 x i32]
%3 = alloca [6 x i8]
%4 = bitcast [100 x i32]* %1 to i8*
%5 = bitcast [5 x i32]* %2 to i8*
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%8 = call i32 @struct_pack(i32* %7, i32 400, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 2013, i32 3, i32 21, i32 0, i32 34, i8 signext 115, i8 signext 116, i8 signext 114, i8 signext 117, i8 signext 99, i8 signext 116)
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32 %8, 26
br i1 %10, label %11, label %19
11: ; preds = %0
%12 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%13 = call i64 (i32*, ...) @memcmp(i32* %7, i32* %12, i64 20)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 20
%17 = call i64 (i32*, ...) @memcmp(i32* %16, i8* %6, i64 6)
%18 = icmp eq i64 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %15, %11, %0
br label %20
20: ; preds = %15, %19
%21 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0), %19 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.4, i64 0, i64 0), %15 ]
%22 = call i32 @puts(i8* dereferenceable(1) %21)
ret void
}