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

/* Variables and functions */
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ printf(char *);
int struct_pack(char *, int, char *, char, int);
void test_struct_example_3_1(void) {
  uint8_t buf[100];
  ssize_t size;
  uint8_t result[] = {'*', 0x00, 0x00, 0x00, 0x15, 0x14, 0x13, 0x12};
  size = struct_pack(buf, sizeof(buf), "ci", '*', 0x12131415);
  printf("Example 3.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_3_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0xebe(%rip),%rax
mov    %rax,-0x7c(%rbp)
lea    -0x70(%rbp),%rdi
mov    $0x64,%esi
lea    0xeb2(%rip),%rdx
mov    $0x2a,%ecx
mov    $0x12131415,%r8d
call   1050 <struct_pack@plt>
mov    %eax,-0x74(%rbp)
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
movslq -0x74(%rbp),%rax
cmp    $0x8,%rax
jne    11b0 <test_struct_example_3_1+0x80>
lea    -0x70(%rbp),%rdi
lea    -0x7c(%rbp),%rsi
mov    $0x8,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11b0 <test_struct_example_3_1+0x80>
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
jmp    11bc <test_struct_example_3_1+0x8c>
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_struct_example_3_1>:
push   %rbx
sub    $0x80,%rsp
movabs $0x121314150000002a,%rax
14 13 12
mov    %rax,0x8(%rsp)
lea    0xea2(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
mov    $0x2a,%ecx
mov    $0x12131415,%r8d
call   1060 <struct_pack@plt>
mov    %eax,%ebx
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
cmp    $0x8,%ebx
jne    11a4 <test_struct_example_3_1+0x64>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     11ad <test_struct_example_3_1+0x6d>
lea    0xe6b(%rip),%rdi
jmp    11b4 <test_struct_example_3_1+0x74>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_struct_example_3_1.result = [8 x i8] c"*\00\00\00\15\14\13\12"
@.str = [3 x i8] c"ci\00"
@.str.1 = [19 x i8] c"Example 3.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_3_1() {
%1 = alloca [100 x i8]
%2 = alloca i32
%3 = alloca [8 x i8]
%4 = bitcast [8 x i8]* %3 to i8*
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%6 = call i32 @struct_pack(i8* %5, i32 100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext 42, i32 303240213)
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, 8
br i1 %10, label %11, label %18
11: ; preds = %0
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%14 = call i64 @memcmp(i8* %12, i8* %13, i32 8)
%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):
@.str = [3 x i8] c"ci\00"
@.str.1 = [19 x i8] c"Example 3.1 test: \00"
@str = [5 x i8] c"FAIL\00"
@str.4 = [5 x i8] c"PASS\00"
define void @test_struct_example_3_1() {
%1 = alloca [100 x i8]
%2 = alloca i64
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = bitcast i64* %2 to i8*
store i64 1302406797667074090, i64* %2
%5 = call i32 @struct_pack(i8* %3, i32 100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext 42, i32 303240213)
%6 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32 %5, 8
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i64 @memcmp(i8* %3, i8* %4, i32 8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %8, %0
br label %12
12: ; preds = %8, %11
%13 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0), %11 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.4, i64 0, i64 0), %8 ]
%14 = call i32 @puts(i8* dereferenceable(1) %13)
ret void
}