#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_4(void) {
  uint8_t buf[100];
  ssize_t size;
  uint8_t result[] = {0x01, 0x00, 0x00, 0x00, 0x02, 0x00,
                      0x00, 0x00, 0x03, 0x00, 0x00, 0x00};
  size = struct_pack(buf, sizeof(buf), "llh0l", 1, 2, 3);
  printf("Example 4 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_4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
lea    -0x1d0(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
movl   $0x1,-0x1d0(%rbp)
movl   $0x2,-0x1c0(%rbp)
movl   $0x3,-0x1b0(%rbp)
lea    -0x190(%rbp),%rdi
mov    $0x190,%esi
lea    0xe71(%rip),%rdx
mov    $0x1,%ecx
mov    $0x2,%r8d
mov    $0x3,%r9d
call   1060 <struct_pack@plt>
mov    %eax,-0x194(%rbp)
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
movslq -0x194(%rbp),%rax
cmp    $0x30,%rax
jne    11fb <test_struct_example_4+0xbb>
lea    -0x190(%rbp),%rdi
lea    -0x1d0(%rbp),%rsi
mov    $0x30,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
jne    11fb <test_struct_example_4+0xbb>
lea    0xe26(%rip),%rdi
call   1030 <printf@plt>
jmp    1207 <test_struct_example_4+0xc7>
lea    0xe1b(%rip),%rdi
call   1030 <printf@plt>
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_struct_example_4>:
push   %rbx
sub    $0x1c0,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movl   $0x1,(%rsp)
movl   $0x2,0x10(%rsp)
movl   $0x3,0x20(%rsp)
lea    0xe89(%rip),%rdx
lea    0x30(%rsp),%rdi
mov    $0x190,%esi
mov    $0x1,%ecx
mov    $0x2,%r8d
mov    $0x3,%r9d
call   1060 <struct_pack@plt>
mov    %eax,%ebx
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
cmp    $0x30,%ebx
jne    11c1 <test_struct_example_4+0x81>
lea    0x30(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x30,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     11ca <test_struct_example_4+0x8a>
lea    0xe4f(%rip),%rdi
jmp    11d1 <test_struct_example_4+0x91>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
add    $0x1c0,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"llh0l\00"
@.str.1 = [17 x i8] c"Example 4 test: \00"
@str = [5 x i8] c"FAIL\00"
@str.4 = [5 x i8] c"PASS\00"
define void @test_struct_example_4() {
%1 = alloca [100 x i32]
%2 = alloca [12 x i32]
%3 = bitcast [100 x i32]* %1 to i8*
%4 = bitcast [12 x i32]* %2 to i8*
%5 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 0
store i32 1, i32* %5
%6 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 4
store i32 2, i32* %6
%7 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 8
store i32 3, i32* %7
%8 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%9 = call i32 @struct_pack(i32* %8, i32 400, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 1, i32 2, i32 3)
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %9, 48
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i64 @memcmp(i32* %8, i32* %5, i32 48)
%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
}