#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 unsigned int uint8_t;
typedef int uint16_t;
struct lcpa_metapack {
  int dummy;
};
typedef scalar_t__ __x;

/* Variables and functions */
struct lcpa_metapack *lcpa_append_copy(struct lcpa_metapack *, char *, int,
                                       unsigned int *);
void lcpf_80211headers(struct lcpa_metapack *pack, unsigned int type,
                       unsigned int subtype, unsigned int fcflags,
                       unsigned int duration, uint8_t *mac1, uint8_t *mac2,
                       uint8_t *mac3, uint8_t *mac4, unsigned int fragment,
                       unsigned int sequence) {
  uint8_t chunk[2];
  uint16_t *sixptr;
  chunk[0] = ((type << 2) | (subtype << 4));
  chunk[1] = (uint8_t)fcflags;
  pack = lcpa_append_copy(pack, "80211FC", 2, chunk);
  sixptr = (uint16_t *)chunk;
  *sixptr = ({
    uint16_t __x = (((uint16_t)duration));
    ((uint16_t)((uint16_t)(((uint16_t)(__x) & (uint16_t)0x00ff) << 8) |
                (uint16_t)(((uint16_t)(__x) & (uint16_t)0xff00) >> 8)));
  });
  pack = lcpa_append_copy(pack, "80211DUR", 2, chunk);
  if (mac1 != NULL)
    pack = lcpa_append_copy(pack, "80211MAC1", 6, mac1);
  if (mac2 != NULL)
    pack = lcpa_append_copy(pack, "80211MAC2", 6, mac2);
  if (mac3 != NULL)
    pack = lcpa_append_copy(pack, "80211MAC3", 6, mac3);
  if (mac4 != NULL)
    pack = lcpa_append_copy(pack, "80211MAC4", 6, mac4);
  *sixptr = ((sequence << 4) | fragment);
  pack = lcpa_append_copy(pack, "80211FRAGSEQ", 2, chunk);
}


x86 assembly (clang, -O0):
<lcpf_80211headers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x30(%rbp),%eax
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x2,%eax
mov    -0x10(%rbp),%ecx
shl    $0x4,%ecx
or     %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rcx
lea    0xe9b(%rip),%rsi
mov    $0x2,%edx
call   1030 <lcpa_append_copy@plt>
mov    %rax,-0x8(%rbp)
lea    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
and    $0xff,%eax
shl    $0x8,%eax
mov    -0x34(%rbp),%ecx
and    $0xff00,%ecx
sar    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rcx
lea    0xe53(%rip),%rsi
mov    $0x2,%edx
call   1030 <lcpa_append_copy@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11eb <lcpf_80211headers+0xdb>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rcx
lea    0xe34(%rip),%rsi
mov    $0x6,%edx
call   1030 <lcpa_append_copy@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,0x10(%rbp)
je     1213 <lcpf_80211headers+0x103>
mov    -0x8(%rbp),%rdi
mov    0x10(%rbp),%rcx
lea    0xe16(%rip),%rsi
mov    $0x6,%edx
call   1030 <lcpa_append_copy@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,0x18(%rbp)
je     123b <lcpf_80211headers+0x12b>
mov    -0x8(%rbp),%rdi
mov    0x18(%rbp),%rcx
lea    0xdf8(%rip),%rsi
mov    $0x6,%edx
call   1030 <lcpa_append_copy@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,0x20(%rbp)
je     1263 <lcpf_80211headers+0x153>
mov    -0x8(%rbp),%rdi
mov    0x20(%rbp),%rcx
lea    0xdda(%rip),%rsi
mov    $0x6,%edx
call   1030 <lcpa_append_copy@plt>
mov    %rax,-0x8(%rbp)
mov    0x30(%rbp),%ecx
shl    $0x4,%ecx
or     0x28(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rcx
lea    0xdb8(%rip),%rsi
mov    $0x2,%edx
call   1030 <lcpa_append_copy@plt>
mov    %rax,-0x8(%rbp)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lcpf_80211headers>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r9,%rbx
mov    %r8d,%ebp
mov    0x30(%rsp),%r14
shl    $0x2,%esi
shl    $0x4,%edx
or     %esi,%edx
mov    %edx,(%rsp)
mov    %ecx,0x4(%rsp)
lea    0xec8(%rip),%rsi
mov    %rsp,%r15
mov    $0x2,%edx
mov    %r15,%rcx
call   1030 <lcpa_append_copy@plt>
rol    $0x8,%bp
movzwl %bp,%ecx
mov    %ecx,(%rsp)
lea    0xeaf(%rip),%rsi
mov    %rax,%rdi
mov    $0x2,%edx
mov    %r15,%rcx
call   1030 <lcpa_append_copy@plt>
test   %rbx,%rbx
je     1185 <lcpf_80211headers+0x75>
lea    0xe9c(%rip),%rsi
mov    %rax,%rdi
mov    $0x6,%edx
mov    %rbx,%rcx
call   1030 <lcpa_append_copy@plt>
mov    0x38(%rsp),%rbx
test   %r14,%r14
je     11a6 <lcpf_80211headers+0x96>
lea    0xe85(%rip),%rsi
mov    %rax,%rdi
mov    $0x6,%edx
mov    %r14,%rcx
call   1030 <lcpa_append_copy@plt>
mov    0x40(%rsp),%r14
test   %rbx,%rbx
je     11c7 <lcpf_80211headers+0xb7>
lea    0xe6e(%rip),%rsi
mov    %rax,%rdi
mov    $0x6,%edx
mov    %rbx,%rcx
call   1030 <lcpa_append_copy@plt>
mov    0x50(%rsp),%ebx
mov    0x48(%rsp),%ebp
test   %r14,%r14
je     11eb <lcpf_80211headers+0xdb>
lea    0xe54(%rip),%rsi
mov    %rax,%rdi
mov    $0x6,%edx
mov    %r14,%rcx
call   1030 <lcpa_append_copy@plt>
shl    $0x4,%ebx
or     %ebp,%ebx
mov    %ebx,(%rsp)
lea    0xe3f(%rip),%rsi
mov    %rsp,%rcx
mov    %rax,%rdi
mov    $0x2,%edx
call   1030 <lcpa_append_copy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.lcpa_metapack = type { i32 }
@.str = [8 x i8] c"80211FC\00"
@.str.1 = [9 x i8] c"80211DUR\00"
@.str.2 = [10 x i8] c"80211MAC1\00"
@.str.3 = [10 x i8] c"80211MAC2\00"
@.str.4 = [10 x i8] c"80211MAC3\00"
@.str.5 = [10 x i8] c"80211MAC4\00"
@.str.6 = [13 x i8] c"80211FRAGSEQ\00"
define void @lcpf_80211headers(%struct.lcpa_metapack* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32* %5, i32* %6, i32* %7, i32* %8, i32 %9, i32 %10) {
%12 = alloca %struct.lcpa_metapack*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i32*
%20 = alloca i32*
%21 = alloca i32
%22 = alloca i32
%23 = alloca [2 x i32]
%24 = alloca i32*
%25 = alloca i32
%26 = alloca i32
store %struct.lcpa_metapack* %0, %struct.lcpa_metapack** %12
store i32 %1, i32* %13
store i32 %2, i32* %14
store i32 %3, i32* %15
store i32 %4, i32* %16
store i32* %5, i32** %17
store i32* %6, i32** %18
store i32* %7, i32** %19
store i32* %8, i32** %20
store i32 %9, i32* %21
store i32 %10, i32* %22
%27 = load i32, i32* %13
%28 = shl i32 %27, 2
%29 = load i32, i32* %14
%30 = shl i32 %29, 4
%31 = or i32 %28, %30
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %23, i64 0, i64 0
store i32 %31, i32* %32
%33 = load i32, i32* %15
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %23, i64 0, i64 1
store i32 %33, i32* %34
%35 = load %struct.lcpa_metapack*, %struct.lcpa_metapack** %12
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %23, i64 0, i64 0
%37 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 2, i32* %36)
store %struct.lcpa_metapack* %37, %struct.lcpa_metapack** %12
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %23, i64 0, i64 0
store i32* %38, i32** %24
%39 = load i32, i32* %16
store i32 %39, i32* %25
%40 = load i32, i32* %25
%41 = and i32 %40, 255
%42 = shl i32 %41, 8
%43 = load i32, i32* %25
%44 = and i32 %43, 65280
%45 = ashr i32 %44, 8
%46 = or i32 %42, %45
store i32 %46, i32* %26
%47 = load i32, i32* %26
%48 = load i32*, i32** %24
store i32 %47, i32* %48
%49 = load %struct.lcpa_metapack*, %struct.lcpa_metapack** %12
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %23, i64 0, i64 0
%51 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %49, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 2, i32* %50)
store %struct.lcpa_metapack* %51, %struct.lcpa_metapack** %12
%52 = load i32*, i32** %17
%53 = icmp ne i32* %52, null
br i1 %53, label %54, label %58
54: ; preds = %11
%55 = load %struct.lcpa_metapack*, %struct.lcpa_metapack** %12
%56 = load i32*, i32** %17
%57 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %55, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 6, i32* %56)
store %struct.lcpa_metapack* %57, %struct.lcpa_metapack** %12
br label %58
58: ; preds = %54, %11
%59 = load i32*, i32** %18
%60 = icmp ne i32* %59, null
br i1 %60, label %61, label %65
61: ; preds = %58
%62 = load %struct.lcpa_metapack*, %struct.lcpa_metapack** %12
%63 = load i32*, i32** %18
%64 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %62, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 6, i32* %63)
store %struct.lcpa_metapack* %64, %struct.lcpa_metapack** %12
br label %65
65: ; preds = %61, %58
%66 = load i32*, i32** %19
%67 = icmp ne i32* %66, null
br i1 %67, label %68, label %72
68: ; preds = %65
%69 = load %struct.lcpa_metapack*, %struct.lcpa_metapack** %12
%70 = load i32*, i32** %19
%71 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %69, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 6, i32* %70)
store %struct.lcpa_metapack* %71, %struct.lcpa_metapack** %12
br label %72
72: ; preds = %68, %65
%73 = load i32*, i32** %20
%74 = icmp ne i32* %73, null
br i1 %74, label %75, label %79
75: ; preds = %72
%76 = load %struct.lcpa_metapack*, %struct.lcpa_metapack** %12
%77 = load i32*, i32** %20
%78 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %76, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 6, i32* %77)
store %struct.lcpa_metapack* %78, %struct.lcpa_metapack** %12
br label %79
79: ; preds = %75, %72
%80 = load i32, i32* %22
%81 = shl i32 %80, 4
%82 = load i32, i32* %21
%83 = or i32 %81, %82
%84 = load i32*, i32** %24
store i32 %83, i32* %84
%85 = load %struct.lcpa_metapack*, %struct.lcpa_metapack** %12
%86 = getelementptr inbounds [2 x i32], [2 x i32]* %23, i64 0, i64 0
%87 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %85, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 2, i32* %86)
store %struct.lcpa_metapack* %87, %struct.lcpa_metapack** %12
ret void
}

LLVM IR (-O2):
%struct.lcpa_metapack = type { i32 }
@.str = [8 x i8] c"80211FC\00"
@.str.1 = [9 x i8] c"80211DUR\00"
@.str.2 = [10 x i8] c"80211MAC1\00"
@.str.3 = [10 x i8] c"80211MAC2\00"
@.str.4 = [10 x i8] c"80211MAC3\00"
@.str.5 = [10 x i8] c"80211MAC4\00"
@.str.6 = [13 x i8] c"80211FRAGSEQ\00"
define void @lcpf_80211headers(%struct.lcpa_metapack* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32* %5, i32* %6, i32* %7, i32* %8, i32 %9, i32 %10) {
%12 = alloca [2 x i32]
%13 = bitcast [2 x i32]* %12 to i8*
%14 = shl i32 %1, 2
%15 = shl i32 %2, 4
%16 = or i32 %15, %14
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
store i32 %16, i32* %17
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 1
store i32 %3, i32* %18
%19 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 2, i32* %17)
%20 = trunc i32 %4 to i16
%21 = call i16 @llvm.bswap.i16(i16 %20)
%22 = zext i16 %21 to i32
store i32 %22, i32* %17
%23 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 2, i32* %17)
%24 = icmp eq i32* %5, null
br i1 %24, label %27, label %25
25: ; preds = %11
%26 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 6, i32* %5)
br label %27
27: ; preds = %25, %11
%28 = phi %struct.lcpa_metapack* [ %26, %25 ], [ %23, %11 ]
%29 = icmp eq i32* %6, null
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 6, i32* %6)
br label %32
32: ; preds = %30, %27
%33 = phi %struct.lcpa_metapack* [ %31, %30 ], [ %28, %27 ]
%34 = icmp eq i32* %7, null
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 6, i32* %7)
br label %37
37: ; preds = %35, %32
%38 = phi %struct.lcpa_metapack* [ %36, %35 ], [ %33, %32 ]
%39 = icmp eq i32* %8, null
br i1 %39, label %42, label %40
40: ; preds = %37
%41 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %38, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 6, i32* %8)
br label %42
42: ; preds = %40, %37
%43 = phi %struct.lcpa_metapack* [ %41, %40 ], [ %38, %37 ]
%44 = shl i32 %10, 4
%45 = or i32 %44, %9
store i32 %45, i32* %17
%46 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %43, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 2, i32* %17)
ret void
}