#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 */
int /*<<< orphan*/ muxdebug(char *);
int lws_mux_subcommand_header(int cmd, int channel, unsigned char *pb,
                              int len) {
  unsigned char *start = pb;
  if (channel == 0) {
    muxdebug("lws_mux_subcommand_header: given ch 0\n");
    *((int *)0) = 0;
  }
  if (channel < 31)
    *pb++ = (channel << 3) | cmd;
  else {
    *pb++ = (31 << 3) | cmd;
    *pb++ = channel >> 8;
    *pb++ = channel;
  }
  if (len <= 253)
    *pb++ = len;
  else {
    if (len <= 65535) {
      *pb++ = 254;
      *pb++ = len >> 8;
      *pb++ = len;
    } else {
      *pb++ = 255;
      *pb++ = len >> 24;
      *pb++ = len >> 16;
      *pb++ = len >> 8;
      *pb++ = len;
    }
  }
  return pb - start;
}


x86 assembly (clang, -O0):
<lws_mux_subcommand_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    114b <lws_mux_subcommand_header+0x3b>
lea    0xec2(%rip),%rdi
call   1030 <muxdebug@plt>
xor    %eax,%eax
movl   $0x0,(%rax)
cmpl   $0x1f,-0x8(%rbp)
jge    1176 <lws_mux_subcommand_header+0x66>
mov    -0x8(%rbp),%eax
shl    $0x3,%eax
or     -0x4(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    11c0 <lws_mux_subcommand_header+0xb0>
mov    -0x4(%rbp),%eax
or     $0xf8,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
cmpl   $0xfd,-0x14(%rbp)
jg     11e8 <lws_mux_subcommand_header+0xd8>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    12b3 <lws_mux_subcommand_header+0x1a3>
cmpl   $0xffff,-0x14(%rbp)
jg     123b <lws_mux_subcommand_header+0x12b>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xfe,(%rax)
mov    -0x14(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    12ae <lws_mux_subcommand_header+0x19e>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xff,(%rax)
mov    -0x14(%rbp),%eax
sar    $0x18,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
sar    $0x10,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    12b3 <lws_mux_subcommand_header+0x1a3>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lws_mux_subcommand_header>:
push   %rbx
test   %esi,%esi
je     11a2 <lws_mux_subcommand_header+0x92>
mov    %esi,%ebx
cmp    $0x1e,%esi
jg     112f <lws_mux_subcommand_header+0x1f>
shl    $0x3,%ebx
or     %edi,%ebx
mov    $0x1,%eax
mov    %rdx,%rsi
jmp    1142 <lws_mux_subcommand_header+0x32>
or     $0xf8,%dil
mov    %dil,(%rdx)
lea    0x2(%rdx),%rsi
mov    %bh,0x1(%rdx)
mov    $0x3,%eax
add    %rdx,%rax
mov    %bl,(%rsi)
mov    $0x1,%esi
mov    %rax,%rdi
cmp    $0xfe,%ecx
jl     119a <lws_mux_subcommand_header+0x8a>
cmp    $0xffff,%ecx
ja     1172 <lws_mux_subcommand_header+0x62>
lea    0x1(%rax),%rbx
movb   $0xfe,(%rax)
mov    $0x3,%esi
mov    $0x2,%edi
jmp    1195 <lws_mux_subcommand_header+0x85>
movb   $0xff,(%rax)
mov    %ecx,%esi
shr    $0x18,%esi
mov    %sil,0x1(%rax)
mov    %ecx,%esi
shr    $0x10,%esi
lea    0x3(%rax),%rbx
mov    %sil,0x2(%rax)
mov    $0x5,%esi
mov    $0x4,%edi
add    %rax,%rdi
mov    %ch,(%rbx)
add    %esi,%eax
mov    %cl,(%rdi)
sub    %edx,%eax
pop    %rbx
ret
lea    0xe57(%rip),%rdi
call   1030 <muxdebug@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"lws_mux_subcommand_header: given ch 0\0A\00"
define i32 @lws_mux_subcommand_header(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i8*, i8** %7
store i8* %10, i8** %9
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = call i32 @muxdebug(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* null
br label %15
15: ; preds = %13, %4
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 31
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load i32, i32* %6
%20 = shl i32 %19, 3
%21 = load i32, i32* %5
%22 = or i32 %20, %21
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %7
store i8 %23, i8* %24
br label %41
26: ; preds = %15
%27 = load i32, i32* %5
%28 = or i32 248, %27
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %7
store i8 %29, i8* %30
%32 = load i32, i32* %6
%33 = ashr i32 %32, 8
%34 = trunc i32 %33 to i8
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %7
store i8 %34, i8* %35
%37 = load i32, i32* %6
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %7
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %7
store i8 %38, i8* %39
br label %41
41: ; preds = %26, %18
%42 = load i32, i32* %8
%43 = icmp sle i32 %42, 253
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = load i32, i32* %8
%46 = trunc i32 %45 to i8
%47 = load i8*, i8** %7
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %7
store i8 %46, i8* %47
br label %87
49: ; preds = %41
%50 = load i32, i32* %8
%51 = icmp sle i32 %50, 65535
br i1 %51, label %52, label %64
52: ; preds = %49
%53 = load i8*, i8** %7
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %7
store i8 -2, i8* %53
%55 = load i32, i32* %8
%56 = ashr i32 %55, 8
%57 = trunc i32 %56 to i8
%58 = load i8*, i8** %7
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %7
store i8 %57, i8* %58
%60 = load i32, i32* %8
%61 = trunc i32 %60 to i8
%62 = load i8*, i8** %7
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %7
store i8 %61, i8* %62
br label %86
64: ; preds = %49
%65 = load i8*, i8** %7
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %7
store i8 -1, i8* %65
%67 = load i32, i32* %8
%68 = ashr i32 %67, 24
%69 = trunc i32 %68 to i8
%70 = load i8*, i8** %7
%71 = getelementptr inbounds i8, i8* %70, i32 1
store i8* %71, i8** %7
store i8 %69, i8* %70
%72 = load i32, i32* %8
%73 = ashr i32 %72, 16
%74 = trunc i32 %73 to i8
%75 = load i8*, i8** %7
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %7
store i8 %74, i8* %75
%77 = load i32, i32* %8
%78 = ashr i32 %77, 8
%79 = trunc i32 %78 to i8
%80 = load i8*, i8** %7
%81 = getelementptr inbounds i8, i8* %80, i32 1
store i8* %81, i8** %7
store i8 %79, i8* %80
%82 = load i32, i32* %8
%83 = trunc i32 %82 to i8
%84 = load i8*, i8** %7
%85 = getelementptr inbounds i8, i8* %84, i32 1
store i8* %85, i8** %7
store i8 %83, i8* %84
br label %86
86: ; preds = %64, %52
br label %87
87: ; preds = %86, %44
%88 = load i8*, i8** %7
%89 = load i8*, i8** %9
%90 = ptrtoint i8* %88 to i64
%91 = ptrtoint i8* %89 to i64
%92 = sub i64 %90, %91
%93 = trunc i64 %92 to i32
ret i32 %93
}

LLVM IR (-O2):
@.str = [39 x i8] c"lws_mux_subcommand_header: given ch 0\0A\00"
define i32 @lws_mux_subcommand_header(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp eq i32 %1, 0
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @muxdebug(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
unreachable
8: ; preds = %4
%9 = icmp slt i32 %1, 31
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = shl i32 %1, 3
%12 = or i32 %11, %0
br label %20
13: ; preds = %8
%14 = trunc i32 %0 to i8
%15 = or i8 %14, -8
%16 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %15, i8* %2
%17 = lshr i32 %1, 8
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds i8, i8* %2, i64 2
store i8 %18, i8* %16
br label %20
20: ; preds = %13, %10
%21 = phi i32 [ %1, %13 ], [ %12, %10 ]
%22 = phi i64 [ 3, %13 ], [ 1, %10 ]
%23 = phi i8* [ %19, %13 ], [ %2, %10 ]
%24 = trunc i32 %21 to i8
%25 = getelementptr inbounds i8, i8* %2, i64 %22
store i8 %24, i8* %23
%26 = icmp slt i32 %3, 254
br i1 %26, label %45, label %27
27: ; preds = %20
%28 = icmp ult i32 %3, 65536
%29 = getelementptr inbounds i8, i8* %25, i64 1
br i1 %28, label %30, label %31
30: ; preds = %27
store i8 -2, i8* %25
br label %38
31: ; preds = %27
store i8 -1, i8* %25
%32 = lshr i32 %3, 24
%33 = trunc i32 %32 to i8
%34 = getelementptr inbounds i8, i8* %25, i64 2
store i8 %33, i8* %29
%35 = lshr i32 %3, 16
%36 = trunc i32 %35 to i8
%37 = getelementptr inbounds i8, i8* %25, i64 3
store i8 %36, i8* %34
br label %38
38: ; preds = %31, %30
%39 = phi i64 [ 2, %30 ], [ 4, %31 ]
%40 = phi i8* [ %29, %30 ], [ %37, %31 ]
%41 = phi i64 [ 3, %30 ], [ 5, %31 ]
%42 = lshr i32 %3, 8
%43 = trunc i32 %42 to i8
%44 = getelementptr inbounds i8, i8* %25, i64 %39
store i8 %43, i8* %40
br label %45
45: ; preds = %38, %20
%46 = phi i64 [ 1, %20 ], [ %41, %38 ]
%47 = phi i8* [ %25, %20 ], [ %44, %38 ]
%48 = trunc i32 %3 to i8
%49 = getelementptr inbounds i8, i8* %25, i64 %46
store i8 %48, i8* %47
%50 = ptrtoint i8* %49 to i64
%51 = ptrtoint i8* %2 to i64
%52 = sub i64 %50, %51
%53 = trunc i64 %52 to i32
ret i32 %53
}