#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 ssize_t;
typedef int /*<<< orphan*/ arr_value;
typedef int /*<<< orphan*/ arr_result;

/* Variables and functions */
scalar_t__ memcmp(int **, int *, int);
int /*<<< orphan*/ printf(char *);
int struct_unpack(int **, int, char *, int *, int *, int *);
void test_struct_unpack_repeat(void) {
  ssize_t size;
  int arr_value[3] = {-1, 100500, 42};
  int arr_result[3];
  size = struct_unpack(&arr_value, sizeof(arr_value), "3i", &arr_result[0],
                       &arr_result[1], &arr_result[2]);
  printf("Unpack repeated values test: ");
  if (size == sizeof(arr_value) &&
      memcmp(&arr_value, arr_result, sizeof(arr_result)) == 0)
    printf("PASS\n");
  else
    printf("FAIL\n");
}


x86 assembly (clang, -O0):
<test_struct_unpack_repeat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xebf(%rip),%eax
mov    %eax,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rcx
lea    -0x1c(%rbp),%r8
add    $0x4,%r8
lea    -0x1c(%rbp),%r9
add    $0x8,%r9
mov    $0xc,%esi
lea    0xe9c(%rip),%rdx
call   1050 <struct_unpack@plt>
mov    %eax,-0x4(%rbp)
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
movslq -0x4(%rbp),%rax
cmp    $0xc,%rax
jne    11bf <test_struct_unpack_repeat+0x8f>
lea    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0xc,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11bf <test_struct_unpack_repeat+0x8f>
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
jmp    11cb <test_struct_unpack_repeat+0x9b>
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_struct_unpack_repeat>:
push   %rbx
sub    $0x20,%rsp
mov    0xebd(%rip),%eax
mov    %eax,0x10(%rsp)
mov    0xeaa(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0x18(%rsp),%r8
lea    0x1c(%rsp),%r9
lea    0xea0(%rip),%rdx
lea    0x8(%rsp),%rdi
lea    0x14(%rsp),%rcx
mov    $0xc,%esi
call   1060 <struct_unpack@plt>
mov    %eax,%ebx
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
cmp    $0xc,%ebx
jne    11ac <test_struct_unpack_repeat+0x6c>
lea    0x8(%rsp),%rdi
lea    0x14(%rsp),%rsi
mov    $0xc,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     11b5 <test_struct_unpack_repeat+0x75>
lea    0xe7a(%rip),%rdi
jmp    11bc <test_struct_unpack_repeat+0x7c>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_struct_unpack_repeat.arr_value = [3 x i32] [i32 -1, i32 100500, i32 42]
@.str = [3 x i8] c"3i\00"
@.str.1 = [30 x i8] c"Unpack 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_unpack_repeat() {
%1 = alloca i32
%2 = alloca [3 x i32]
%3 = alloca [3 x i32]
%4 = bitcast [3 x i32]* %2 to i8*
%5 = bitcast [3 x i32]* %2 to i32**
%6 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 1
%8 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 2
%9 = call i32 @struct_unpack(i32** %5, i32 12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8)
store i32 %9, i32* %1
%10 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* %1
%12 = sext i32 %11 to i64
%13 = icmp eq i64 %12, 12
br i1 %13, label %14, label %21
14: ; preds = %0
%15 = bitcast [3 x i32]* %2 to i32**
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%17 = call i64 @memcmp(i32** %15, i32* %16, i32 12)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %23
21: ; preds = %14, %0
%22 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %19
ret void
}

LLVM IR (-O2):
@__const.test_struct_unpack_repeat.arr_value = [3 x i32] [i32 -1, i32 100500, i32 42]
@.str = [3 x i8] c"3i\00"
@.str.1 = [30 x i8] c"Unpack repeated values test: \00"
@str = [5 x i8] c"FAIL\00"
@str.4 = [5 x i8] c"PASS\00"
define void @test_struct_unpack_repeat() {
%1 = alloca [3 x i32]
%2 = alloca [3 x i32]
%3 = bitcast [3 x i32]* %1 to i8*
%4 = bitcast [3 x i32]* %2 to i8*
%5 = bitcast [3 x i32]* %1 to i32**
%6 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 1
%8 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 2
%9 = call i32 @struct_unpack(i32** %5, i32 12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8)
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %9, 12
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i64 @memcmp(i32** %5, i32* %6, i32 12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %12, %0
br label %16
16: ; preds = %12, %15
%17 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0), %15 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.4, i64 0, i64 0), %12 ]
%18 = call i32 @puts(i8* dereferenceable(1) %17)
ret void
}