#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_80211ctrlheaders(struct lcpa_metapack *pack, unsigned int type,
                           unsigned int subtype, unsigned int fcflags,
                           unsigned int duration, uint8_t *mac1) {
  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);
  }
  return;
}


x86 assembly (clang, -O0):
<lcpf_80211ctrlheaders>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
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    0xead(%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    0xe65(%rip),%rsi
mov    $0x2,%edx
call   1030 <lcpa_append_copy@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d9 <lcpf_80211ctrlheaders+0xc9>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rcx
lea    0xe46(%rip),%rsi
mov    $0x6,%edx
call   1030 <lcpa_append_copy@plt>
mov    %rax,-0x8(%rbp)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lcpf_80211ctrlheaders>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %r9,%rbx
mov    %r8d,%ebp
shl    $0x2,%esi
shl    $0x4,%edx
or     %esi,%edx
mov    %edx,0x8(%rsp)
mov    %ecx,0xc(%rsp)
lea    0xecb(%rip),%rsi
lea    0x8(%rsp),%r14
mov    $0x2,%edx
mov    %r14,%rcx
call   1030 <lcpa_append_copy@plt>
rol    $0x8,%bp
movzwl %bp,%ecx
mov    %ecx,0x8(%rsp)
lea    0xeaf(%rip),%rsi
mov    %rax,%rdi
mov    $0x2,%edx
mov    %r14,%rcx
call   1030 <lcpa_append_copy@plt>
test   %rbx,%rbx
je     1185 <lcpf_80211ctrlheaders+0x75>
lea    0xe9c(%rip),%rsi
mov    %rax,%rdi
mov    $0x6,%edx
mov    %rbx,%rcx
call   1030 <lcpa_append_copy@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
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"
define void @lcpf_80211ctrlheaders(%struct.lcpa_metapack* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32* %5) {
%7 = alloca %struct.lcpa_metapack*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca [2 x i32]
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
store %struct.lcpa_metapack* %0, %struct.lcpa_metapack** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32* %5, i32** %12
%17 = load i32, i32* %8
%18 = shl i32 %17, 2
%19 = load i32, i32* %9
%20 = shl i32 %19, 4
%21 = or i32 %18, %20
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
store i32 %21, i32* %22
%23 = load i32, i32* %10
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 1
store i32 %23, i32* %24
%25 = load %struct.lcpa_metapack*, %struct.lcpa_metapack** %7
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%27 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 2, i32* %26)
store %struct.lcpa_metapack* %27, %struct.lcpa_metapack** %7
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
store i32* %28, i32** %14
%29 = load i32, i32* %11
store i32 %29, i32* %15
%30 = load i32, i32* %15
%31 = and i32 %30, 255
%32 = shl i32 %31, 8
%33 = load i32, i32* %15
%34 = and i32 %33, 65280
%35 = ashr i32 %34, 8
%36 = or i32 %32, %35
store i32 %36, i32* %16
%37 = load i32, i32* %16
%38 = load i32*, i32** %14
store i32 %37, i32* %38
%39 = load %struct.lcpa_metapack*, %struct.lcpa_metapack** %7
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%41 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %39, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 2, i32* %40)
store %struct.lcpa_metapack* %41, %struct.lcpa_metapack** %7
%42 = load i32*, i32** %12
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %48
44: ; preds = %6
%45 = load %struct.lcpa_metapack*, %struct.lcpa_metapack** %7
%46 = load i32*, i32** %12
%47 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %45, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 6, i32* %46)
store %struct.lcpa_metapack* %47, %struct.lcpa_metapack** %7
br label %48
48: ; preds = %44, %6
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"
define void @lcpf_80211ctrlheaders(%struct.lcpa_metapack* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32* %5) {
%7 = alloca [2 x i32]
%8 = bitcast [2 x i32]* %7 to i8*
%9 = shl i32 %1, 2
%10 = shl i32 %2, 4
%11 = or i32 %10, %9
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
store i32 %11, i32* %12
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
store i32 %3, i32* %13
%14 = 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* %12)
%15 = trunc i32 %4 to i16
%16 = call i16 @llvm.bswap.i16(i16 %15)
%17 = zext i16 %16 to i32
store i32 %17, i32* %12
%18 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 2, i32* %12)
%19 = icmp eq i32* %5, null
br i1 %19, label %22, label %20
20: ; preds = %6
%21 = call %struct.lcpa_metapack* @lcpa_append_copy(%struct.lcpa_metapack* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 6, i32* %5)
br label %22
22: ; preds = %20, %6
ret void
}