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

/* Variables and functions */
scalar_t__ memcmp(int *, int *, int);
int /*<<< orphan*/ printf(char *);
int struct_pack(int *, int, char *, int, char);
void test_struct_example_3_2(void) {
  uint8_t buf[100];
  ssize_t size;
  uint8_t result[] = {0x15, 0x14, 0x13, 0x12, '*'};
  size = struct_pack(buf, sizeof(buf), "ic", 0x12131415, '*');
  printf("Example 3.2 test: ");
  if (size == sizeof(result) && memcmp(buf, result, sizeof(result)) == 0)
    printf("PASS\n");
  else
    printf("FAIL\n");
}


x86 assembly (clang, -O0):
<test_struct_example_3_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    0xebe(%rip),%rax
mov    %rax,-0x1b0(%rbp)
mov    0xeb8(%rip),%rax
mov    %rax,-0x1a8(%rbp)
mov    0xeb3(%rip),%eax
mov    %eax,-0x1a0(%rbp)
lea    -0x190(%rbp),%rdi
mov    $0x190,%esi
lea    0xe9e(%rip),%rdx
mov    $0x12131415,%ecx
mov    $0x2a,%r8d
call   1050 <struct_pack@plt>
mov    %eax,-0x194(%rbp)
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
movslq -0x194(%rbp),%rax
cmp    $0x14,%rax
jne    11dc <test_struct_example_3_2+0xac>
lea    -0x190(%rbp),%rdi
lea    -0x1b0(%rbp),%rsi
mov    $0x14,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11dc <test_struct_example_3_2+0xac>
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
jmp    11e8 <test_struct_example_3_2+0xb8>
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_struct_example_3_2>:
push   %rbx
sub    $0x1b0,%rsp
mov    0xec2(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xea7(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xeb0(%rip),%rdx
lea    0x20(%rsp),%rdi
mov    $0x190,%esi
mov    $0x12131415,%ecx
mov    $0x2a,%r8d
call   1060 <struct_pack@plt>
mov    %eax,%ebx
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
cmp    $0x14,%ebx
jne    11a8 <test_struct_example_3_2+0x68>
lea    0x20(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x14,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     11b1 <test_struct_example_3_2+0x71>
lea    0xe7b(%rip),%rdi
jmp    11b8 <test_struct_example_3_2+0x78>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
add    $0x1b0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_struct_example_3_2.result = [5 x i32] [i32 21, i32 20, i32 19, i32 18, i32 42]
@.str = [3 x i8] c"ic\00"
@.str.1 = [19 x i8] c"Example 3.2 test: \00"
@.str.2 = [6 x i8] c"PASS\0A\00"
@.str.3 = [6 x i8] c"FAIL\0A\00"
define void @test_struct_example_3_2() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = alloca [5 x i32]
%4 = bitcast [5 x i32]* %3 to i8*
%5 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%6 = call i32 @struct_pack(i32* %5, i32 400, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 303240213, i8 signext 42)
store i32 %6, i32* %2
%7 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = icmp eq i64 %9, 20
br i1 %10, label %11, label %18
11: ; preds = %0
%12 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%13 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%14 = call i64 @memcmp(i32* %12, i32* %13, i32 20)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %20
18: ; preds = %11, %0
%19 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
ret void
}

LLVM IR (-O2):
@__const.test_struct_example_3_2.result = [5 x i32] [i32 21, i32 20, i32 19, i32 18, i32 42]
@.str = [3 x i8] c"ic\00"
@.str.1 = [19 x i8] c"Example 3.2 test: \00"
@str = [5 x i8] c"FAIL\00"
@str.4 = [5 x i8] c"PASS\00"
define void @test_struct_example_3_2() {
%1 = alloca [100 x i32]
%2 = alloca [5 x i32]
%3 = bitcast [100 x i32]* %1 to i8*
%4 = bitcast [5 x i32]* %2 to i8*
%5 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%6 = call i32 @struct_pack(i32* %5, i32 400, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 303240213, i8 signext 42)
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32 %6, 20
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%11 = call i64 @memcmp(i32* %5, i32* %10, i32 20)
%12 = icmp eq i64 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %9, %0
br label %14
14: ; preds = %9, %13
%15 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0), %13 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.4, i64 0, i64 0), %9 ]
%16 = call i32 @puts(i8* dereferenceable(1) %15)
ret void
}