#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 */

/* Variables and functions */
unsigned int prbs15_next_28_bits(unsigned short, unsigned short *);
unsigned short prbs15_next_7_bytes(unsigned short seed_rev,
                                   unsigned char buf[(7)], int reserve_output) {
  unsigned short next_seed;
  unsigned int prbs_bits_0_27, prbs_bits_28_55;
  prbs_bits_0_27 = prbs15_next_28_bits(seed_rev, &next_seed);
  prbs_bits_28_55 = prbs15_next_28_bits(next_seed, &next_seed);
  if (reserve_output) {
    prbs_bits_0_27 = ~prbs_bits_0_27;
    prbs_bits_28_55 = ~prbs_bits_28_55;
  }
  buf[0] = 0xFF & (prbs_bits_0_27);
  buf[1] = 0xFF & (prbs_bits_0_27 >> 8);
  buf[2] = 0xFF & (prbs_bits_0_27 >> 16);
  buf[3] = (prbs_bits_0_27 >> 24) | (0xFF & (prbs_bits_28_55 << 4));
  buf[4] = 0xFF & (prbs_bits_28_55 >> 4);
  buf[5] = 0xFF & (prbs_bits_28_55 >> 12);
  buf[6] = 0xFF & (prbs_bits_28_55 >> 20);
  return next_seed;
}


x86 assembly (clang, -O0):
<prbs15_next_7_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x16(%rbp),%rsi
movzwl -0x2(%rbp),%edi
call   1030 <prbs15_next_28_bits@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x16(%rbp),%rsi
movzwl -0x16(%rbp),%edi
call   1030 <prbs15_next_28_bits@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1162 <prbs15_next_7_bytes+0x52>
mov    -0x1c(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x1c(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x1c(%rbp),%eax
shr    $0x18,%eax
mov    -0x20(%rbp),%ecx
shl    $0x4,%ecx
and    $0xff,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x20(%rbp),%eax
shr    $0x4,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x20(%rbp),%eax
shr    $0xc,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x20(%rbp),%eax
shr    $0x14,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x6(%rax)
movzwl -0x16(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prbs15_next_7_bytes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbp
lea    0x6(%rsp),%r15
mov    %r15,%rsi
call   1030 <prbs15_next_28_bits@plt>
mov    %eax,%ebx
movzwl 0x6(%rsp),%edi
mov    %r15,%rsi
call   1030 <prbs15_next_28_bits@plt>
neg    %r14d
sbb    %ecx,%ecx
xor    %ecx,%ebx
xor    %ecx,%eax
mov    %bl,0x0(%rbp)
mov    %bh,0x1(%rbp)
mov    %ebx,%ecx
shr    $0x10,%ecx
mov    %cl,0x2(%rbp)
shr    $0x18,%ebx
mov    %eax,%ecx
shl    $0x4,%ecx
or     %ebx,%ecx
mov    %cl,0x3(%rbp)
mov    %eax,%ecx
shr    $0x4,%ecx
mov    %cl,0x4(%rbp)
mov    %eax,%ecx
shr    $0xc,%ecx
mov    %cl,0x5(%rbp)
shr    $0x14,%eax
mov    %al,0x6(%rbp)
movzwl 0x6(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i16 @prbs15_next_7_bytes(i16 zeroext %0, i8* %1, i32 %2) {
%4 = alloca i16
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i16
%8 = alloca i32
%9 = alloca i32
store i16 %0, i16* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i16, i16* %4
%11 = call i32 @prbs15_next_28_bits(i16 zeroext %10, i16* %7)
store i32 %11, i32* %8
%12 = load i16, i16* %7
%13 = call i32 @prbs15_next_28_bits(i16 zeroext %12, i16* %7)
store i32 %13, i32* %9
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %3
%17 = load i32, i32* %8
%18 = xor i32 %17, -1
store i32 %18, i32* %8
%19 = load i32, i32* %9
%20 = xor i32 %19, -1
store i32 %20, i32* %9
br label %21
21: ; preds = %16, %3
%22 = load i32, i32* %8
%23 = and i32 255, %22
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 0
store i8 %24, i8* %26
%27 = load i32, i32* %8
%28 = lshr i32 %27, 8
%29 = and i32 255, %28
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8 %30, i8* %32
%33 = load i32, i32* %8
%34 = lshr i32 %33, 16
%35 = and i32 255, %34
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 2
store i8 %36, i8* %38
%39 = load i32, i32* %8
%40 = lshr i32 %39, 24
%41 = load i32, i32* %9
%42 = shl i32 %41, 4
%43 = and i32 255, %42
%44 = or i32 %40, %43
%45 = trunc i32 %44 to i8
%46 = load i8*, i8** %5
%47 = getelementptr inbounds i8, i8* %46, i64 3
store i8 %45, i8* %47
%48 = load i32, i32* %9
%49 = lshr i32 %48, 4
%50 = and i32 255, %49
%51 = trunc i32 %50 to i8
%52 = load i8*, i8** %5
%53 = getelementptr inbounds i8, i8* %52, i64 4
store i8 %51, i8* %53
%54 = load i32, i32* %9
%55 = lshr i32 %54, 12
%56 = and i32 255, %55
%57 = trunc i32 %56 to i8
%58 = load i8*, i8** %5
%59 = getelementptr inbounds i8, i8* %58, i64 5
store i8 %57, i8* %59
%60 = load i32, i32* %9
%61 = lshr i32 %60, 20
%62 = and i32 255, %61
%63 = trunc i32 %62 to i8
%64 = load i8*, i8** %5
%65 = getelementptr inbounds i8, i8* %64, i64 6
store i8 %63, i8* %65
%66 = load i16, i16* %7
ret i16 %66
}

LLVM IR (-O2):
define zeroext i16 @prbs15_next_7_bytes(i16 zeroext %0, i8* nocapture writeonly %1, i32 %2) {
%4 = alloca i16
%5 = bitcast i16* %4 to i8*
%6 = call i32 @prbs15_next_28_bits(i16 zeroext %0, i16* %4)
%7 = load i16, i16* %4
%8 = call i32 @prbs15_next_28_bits(i16 zeroext %7, i16* %4)
%9 = icmp ne i32 %2, 0
%10 = sext i1 %9 to i32
%11 = xor i32 %6, %10
%12 = xor i32 %8, %10
%13 = trunc i32 %11 to i8
store i8 %13, i8* %1
%14 = lshr i32 %11, 8
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %15, i8* %16
%17 = lshr i32 %11, 16
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %18, i8* %19
%20 = lshr i32 %11, 24
%21 = shl i32 %12, 4
%22 = or i32 %21, %20
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %23, i8* %24
%25 = lshr i32 %12, 4
%26 = trunc i32 %25 to i8
%27 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %26, i8* %27
%28 = lshr i32 %12, 12
%29 = trunc i32 %28 to i8
%30 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %29, i8* %30
%31 = lshr i32 %12, 20
%32 = trunc i32 %31 to i8
%33 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %32, i8* %33
%34 = load i16, i16* %4
ret i16 %34
}