#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, int, int);
void test_struct_example_1_1(void) {
  uint8_t buf[100];
  ssize_t size;
  uint8_t result[] = {0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00};
  size = struct_pack(buf, sizeof(buf), "hhl", 1, 2, 3);
  printf("Example 1.1 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_1_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
mov    0xebe(%rip),%rax
mov    %rax,-0x1c0(%rbp)
mov    0xeb8(%rip),%rax
mov    %rax,-0x1b8(%rbp)
mov    0xeb2(%rip),%rax
mov    %rax,-0x1b0(%rbp)
mov    0xeac(%rip),%rax
mov    %rax,-0x1a8(%rbp)
lea    -0x190(%rbp),%rdi
mov    $0x190,%esi
lea    0xe9a(%rip),%rdx
mov    $0x1,%ecx
mov    $0x2,%r8d
mov    $0x3,%r9d
call   1050 <struct_pack@plt>
mov    %eax,-0x194(%rbp)
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
movslq -0x194(%rbp),%rax
cmp    $0x20,%rax
jne    11f2 <test_struct_example_1_1+0xc2>
lea    -0x190(%rbp),%rdi
lea    -0x1c0(%rbp),%rsi
mov    $0x20,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11f2 <test_struct_example_1_1+0xc2>
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
jmp    11fe <test_struct_example_1_1+0xce>
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_struct_example_1_1>:
push   %rbx
sub    $0x1b0,%rsp
movaps 0xec1(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xea5(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xeba(%rip),%rdx
lea    0x20(%rsp),%rdi
mov    $0x190,%esi
mov    $0x1,%ecx
mov    $0x2,%r8d
mov    $0x3,%r9d
call   1060 <struct_pack@plt>
mov    %eax,%ebx
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
cmp    $0x20,%ebx
jne    11b0 <test_struct_example_1_1+0x70>
lea    0x20(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x20,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     11b9 <test_struct_example_1_1+0x79>
lea    0xe80(%rip),%rdi
jmp    11c0 <test_struct_example_1_1+0x80>
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
add    $0x1b0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_struct_example_1_1.result = [8 x i32] [i32 1, i32 0, i32 2, i32 0, i32 3, i32 0, i32 0, i32 0]
@.str = [4 x i8] c"hhl\00"
@.str.1 = [19 x i8] c"Example 1.1 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_1_1() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = alloca [8 x i32]
%4 = bitcast [8 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 ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 1, i32 2, i32 3)
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, 32
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 [8 x i32], [8 x i32]* %3, i64 0, i64 0
%14 = call i64 @memcmp(i32* %12, i32* %13, i32 32)
%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_1_1.result = [8 x i32] [i32 1, i32 0, i32 2, i32 0, i32 3, i32 0, i32 0, i32 0]
@.str = [4 x i8] c"hhl\00"
@.str.1 = [19 x i8] c"Example 1.1 test: \00"
@str = [5 x i8] c"FAIL\00"
@str.4 = [5 x i8] c"PASS\00"
define void @test_struct_example_1_1() {
%1 = alloca [100 x i32]
%2 = alloca [8 x i32]
%3 = bitcast [100 x i32]* %1 to i8*
%4 = bitcast [8 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 ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 1, i32 2, i32 3)
%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, 32
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%11 = call i64 @memcmp(i32* %5, i32* %10, i32 32)
%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
}