#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 uint64_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int *, void *, int);
uint64_t websocket_server_wrap(void *target, void *msg, uint64_t len,
                               unsigned char opcode, unsigned char first,
                               unsigned char last, unsigned char rsv) {
  ((uint8_t *)target)[0] =
      0 | (((first ? opcode : 0) & 15)) | ((rsv & 7) << 4) | ((last & 1) << 7);
  if (len < 126) {
    ((uint8_t *)target)[1] = len;
    memcpy(((uint8_t *)target) + 2, msg, len);
    return len + 2;
  } else if (len < (1UL << 16)) {
    ((uint8_t *)target)[1] = 126;
    do {
      ((uint8_t *)(((uint8_t *)target + 2)))[0] = ((uint16_t)(len) >> 8) & 0xFF;
      ((uint8_t *)(((uint8_t *)target + 2)))[1] = ((uint16_t)(len)) & 0xFF;
    } while (0);
    ;
    memcpy((uint8_t *)target + 4, msg, len);
    return len + 4;
  }
  ((uint8_t *)target)[1] = 127;
  do {
    ((uint8_t *)(((uint8_t *)target + 2)))[0] = ((uint64_t)(len) >> 56) & 0xFF;
    ((uint8_t *)(((uint8_t *)target + 2)))[1] = ((uint64_t)(len) >> 48) & 0xFF;
    ((uint8_t *)(((uint8_t *)target + 2)))[2] = ((uint64_t)(len) >> 40) & 0xFF;
    ((uint8_t *)(((uint8_t *)target + 2)))[3] = ((uint64_t)(len) >> 32) & 0xFF;
    ((uint8_t *)(((uint8_t *)target + 2)))[4] = ((uint64_t)(len) >> 24) & 0xFF;
    ((uint8_t *)(((uint8_t *)target + 2)))[5] = ((uint64_t)(len) >> 16) & 0xFF;
    ((uint8_t *)(((uint8_t *)target + 2)))[6] = ((uint64_t)(len) >> 8) & 0xFF;
    ((uint8_t *)(((uint8_t *)target + 2)))[7] = ((uint64_t)(len)) & 0xFF;
  } while (0);
  ;
  memcpy((uint8_t *)target + 10, msg, len);
  return len + 10;
}


x86 assembly (clang, -O0):
<websocket_server_wrap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r8d,-0x34(%rbp)
mov    %ecx,%eax
mov    -0x34(%rbp),%ecx
mov    %eax,-0x30(%rbp)
mov    %edx,%eax
mov    -0x30(%rbp),%edx
mov    %eax,-0x2c(%rbp)
mov    %rsi,%rax
mov    -0x2c(%rbp),%esi
mov    %rax,-0x28(%rbp)
mov    %rdi,%r8
mov    -0x28(%rbp),%rdi
mov    %r9b,%al
mov    0x10(%rbp),%r9b
mov    %r8,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %dl,-0x1d(%rbp)
mov    %cl,-0x1e(%rbp)
mov    %al,-0x1f(%rbp)
movzbl -0x1e(%rbp),%eax
cmp    $0x0,%eax
je     1171 <websocket_server_wrap+0x61>
movzbl -0x1d(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    117b <websocket_server_wrap+0x6b>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
jmp    117b <websocket_server_wrap+0x6b>
mov    -0x38(%rbp),%ecx
and    $0xf,%ecx
or     $0x0,%ecx
movzbl 0x10(%rbp),%eax
and    $0x7,%eax
shl    $0x4,%eax
or     %eax,%ecx
movzbl -0x1f(%rbp),%eax
and    $0x1,%eax
shl    $0x7,%eax
or     %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x7e,-0x1c(%rbp)
jge    11d8 <websocket_server_wrap+0xc8>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4(%rbp)
jmp    1312 <websocket_server_wrap+0x202>
movslq -0x1c(%rbp),%rax
cmp    $0x10000,%rax
jae    1238 <websocket_server_wrap+0x128>
mov    -0x10(%rbp),%rax
movl   $0x7e,0x4(%rax)
mov    -0x1c(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x1c(%rbp),%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x10(%rbp),%rdi
add    $0x10,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x4(%rbp)
jmp    1312 <websocket_server_wrap+0x202>
jmp    123d <websocket_server_wrap+0x12d>
mov    -0x10(%rbp),%rax
movl   $0x7f,0x4(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x38,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x30,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x28,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x1c(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0x1c(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x1c(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x1c(%rax)
mov    -0x1c(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x20(%rax)
mov    -0x1c(%rbp),%ecx
and    $0xff,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x24(%rax)
mov    -0x10(%rbp),%rdi
add    $0x28,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<websocket_server_wrap>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
mov    0x20(%rsp),%al
and    $0xf,%cl
test   %r8d,%r8d
movzbl %cl,%ecx
cmove  %r8d,%ecx
shl    $0x4,%al
and    $0x70,%al
shl    $0x7,%r9b
or     %cl,%r9b
or     %al,%r9b
movzbl %r9b,%eax
mov    %eax,(%rdi)
cmp    $0x7e,%edx
jge    1153 <websocket_server_wrap+0x43>
mov    $0x2,%ebp
mov    $0x8,%eax
mov    $0x4,%ecx
mov    %ebx,%edx
jmp    11b7 <websocket_server_wrap+0xa7>
cmp    $0xffff,%ebx
ja     117e <websocket_server_wrap+0x6e>
movl   $0x7e,0x4(%rdi)
mov    %ebx,%edx
shr    $0x8,%edx
mov    $0x4,%ebp
mov    $0x10,%eax
mov    $0xc,%ecx
mov    $0x8,%r8d
jmp    11b0 <websocket_server_wrap+0xa0>
movl   $0x7f,0x4(%rdi)
mov    %ebx,%eax
shr    $0x18,%eax
mov    %eax,0x18(%rdi)
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%eax
mov    %eax,0x1c(%rdi)
movzbl %bh,%edx
mov    $0xa,%ebp
mov    $0x28,%eax
mov    $0x24,%ecx
mov    $0x20,%r8d
mov    %edx,(%rdi,%r8,1)
movzbl %bl,%edx
mov    %edx,(%rdi,%rcx,1)
add    %rdi,%rax
mov    %rax,%rdi
mov    %ebx,%edx
call   1030 <memcpy@plt>
add    %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @websocket_server_wrap(i8* %0, i8* %1, i32 %2, i8 zeroext %3, i8 zeroext %4, i8 zeroext %5, i8 zeroext %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8
%13 = alloca i8
%14 = alloca i8
%15 = alloca i8
store i8* %0, i8** %9
store i8* %1, i8** %10
store i32 %2, i32* %11
store i8 %3, i8* %12
store i8 %4, i8* %13
store i8 %5, i8* %14
store i8 %6, i8* %15
%16 = load i8, i8* %13
%17 = zext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %7
%20 = load i8, i8* %12
%21 = zext i8 %20 to i32
br label %23
22: ; preds = %7
br label %23
23: ; preds = %22, %19
%24 = phi i32 [ %21, %19 ], [ 0, %22 ]
%25 = and i32 %24, 15
%26 = or i32 0, %25
%27 = load i8, i8* %15
%28 = zext i8 %27 to i32
%29 = and i32 %28, 7
%30 = shl i32 %29, 4
%31 = or i32 %26, %30
%32 = load i8, i8* %14
%33 = zext i8 %32 to i32
%34 = and i32 %33, 1
%35 = shl i32 %34, 7
%36 = or i32 %31, %35
%37 = load i8*, i8** %9
%38 = bitcast i8* %37 to i32*
%39 = getelementptr inbounds i32, i32* %38, i64 0
store i32 %36, i32* %39
%40 = load i32, i32* %11
%41 = icmp slt i32 %40, 126
br i1 %41, label %42, label %55
42: ; preds = %23
%43 = load i32, i32* %11
%44 = load i8*, i8** %9
%45 = bitcast i8* %44 to i32*
%46 = getelementptr inbounds i32, i32* %45, i64 1
store i32 %43, i32* %46
%47 = load i8*, i8** %9
%48 = bitcast i8* %47 to i32*
%49 = getelementptr inbounds i32, i32* %48, i64 2
%50 = load i8*, i8** %10
%51 = load i32, i32* %11
%52 = call i32 @memcpy(i32* %49, i8* %50, i32 %51)
%53 = load i32, i32* %11
%54 = add nsw i32 %53, 2
store i32 %54, i32* %8
br label %156
55: ; preds = %23
%56 = load i32, i32* %11
%57 = sext i32 %56 to i64
%58 = icmp ult i64 %57, 65536
br i1 %58, label %59, label %86
59: ; preds = %55
%60 = load i8*, i8** %9
%61 = bitcast i8* %60 to i32*
%62 = getelementptr inbounds i32, i32* %61, i64 1
store i32 126, i32* %62
br label %63
63: ; preds = %59
%64 = load i32, i32* %11
%65 = ashr i32 %64, 8
%66 = and i32 %65, 255
%67 = load i8*, i8** %9
%68 = bitcast i8* %67 to i32*
%69 = getelementptr inbounds i32, i32* %68, i64 2
%70 = getelementptr inbounds i32, i32* %69, i64 0
store i32 %66, i32* %70
%71 = load i32, i32* %11
%72 = and i32 %71, 255
%73 = load i8*, i8** %9
%74 = bitcast i8* %73 to i32*
%75 = getelementptr inbounds i32, i32* %74, i64 2
%76 = getelementptr inbounds i32, i32* %75, i64 1
store i32 %72, i32* %76
br label %77
77: ; preds = %63
%78 = load i8*, i8** %9
%79 = bitcast i8* %78 to i32*
%80 = getelementptr inbounds i32, i32* %79, i64 4
%81 = load i8*, i8** %10
%82 = load i32, i32* %11
%83 = call i32 @memcpy(i32* %80, i8* %81, i32 %82)
%84 = load i32, i32* %11
%85 = add nsw i32 %84, 4
store i32 %85, i32* %8
br label %156
86: ; preds = %55
br label %87
87: ; preds = %86
%88 = load i8*, i8** %9
%89 = bitcast i8* %88 to i32*
%90 = getelementptr inbounds i32, i32* %89, i64 1
store i32 127, i32* %90
br label %91
91: ; preds = %87
%92 = load i32, i32* %11
%93 = ashr i32 %92, 56
%94 = and i32 %93, 255
%95 = load i8*, i8** %9
%96 = bitcast i8* %95 to i32*
%97 = getelementptr inbounds i32, i32* %96, i64 2
%98 = getelementptr inbounds i32, i32* %97, i64 0
store i32 %94, i32* %98
%99 = load i32, i32* %11
%100 = ashr i32 %99, 48
%101 = and i32 %100, 255
%102 = load i8*, i8** %9
%103 = bitcast i8* %102 to i32*
%104 = getelementptr inbounds i32, i32* %103, i64 2
%105 = getelementptr inbounds i32, i32* %104, i64 1
store i32 %101, i32* %105
%106 = load i32, i32* %11
%107 = ashr i32 %106, 40
%108 = and i32 %107, 255
%109 = load i8*, i8** %9
%110 = bitcast i8* %109 to i32*
%111 = getelementptr inbounds i32, i32* %110, i64 2
%112 = getelementptr inbounds i32, i32* %111, i64 2
store i32 %108, i32* %112
%113 = load i32, i32* %11
%114 = ashr i32 %113, 32
%115 = and i32 %114, 255
%116 = load i8*, i8** %9
%117 = bitcast i8* %116 to i32*
%118 = getelementptr inbounds i32, i32* %117, i64 2
%119 = getelementptr inbounds i32, i32* %118, i64 3
store i32 %115, i32* %119
%120 = load i32, i32* %11
%121 = ashr i32 %120, 24
%122 = and i32 %121, 255
%123 = load i8*, i8** %9
%124 = bitcast i8* %123 to i32*
%125 = getelementptr inbounds i32, i32* %124, i64 2
%126 = getelementptr inbounds i32, i32* %125, i64 4
store i32 %122, i32* %126
%127 = load i32, i32* %11
%128 = ashr i32 %127, 16
%129 = and i32 %128, 255
%130 = load i8*, i8** %9
%131 = bitcast i8* %130 to i32*
%132 = getelementptr inbounds i32, i32* %131, i64 2
%133 = getelementptr inbounds i32, i32* %132, i64 5
store i32 %129, i32* %133
%134 = load i32, i32* %11
%135 = ashr i32 %134, 8
%136 = and i32 %135, 255
%137 = load i8*, i8** %9
%138 = bitcast i8* %137 to i32*
%139 = getelementptr inbounds i32, i32* %138, i64 2
%140 = getelementptr inbounds i32, i32* %139, i64 6
store i32 %136, i32* %140
%141 = load i32, i32* %11
%142 = and i32 %141, 255
%143 = load i8*, i8** %9
%144 = bitcast i8* %143 to i32*
%145 = getelementptr inbounds i32, i32* %144, i64 2
%146 = getelementptr inbounds i32, i32* %145, i64 7
store i32 %142, i32* %146
br label %147
147: ; preds = %91
%148 = load i8*, i8** %9
%149 = bitcast i8* %148 to i32*
%150 = getelementptr inbounds i32, i32* %149, i64 10
%151 = load i8*, i8** %10
%152 = load i32, i32* %11
%153 = call i32 @memcpy(i32* %150, i8* %151, i32 %152)
%154 = load i32, i32* %11
%155 = add nsw i32 %154, 10
store i32 %155, i32* %8
br label %156
156: ; preds = %147, %77, %42
%157 = load i32, i32* %8
ret i32 %157
}

LLVM IR (-O2):
define i32 @websocket_server_wrap(i8* %0, i8* %1, i32 %2, i8 zeroext %3, i8 zeroext %4, i8 zeroext %5, i8 zeroext %6) {
%8 = icmp eq i8 %4, 0
%9 = and i8 %3, 15
%10 = select i1 %8, i8 0, i8 %9
%11 = shl i8 %6, 4
%12 = and i8 %11, 112
%13 = or i8 %10, %12
%14 = shl i8 %5, 7
%15 = or i8 %13, %14
%16 = zext i8 %15 to i32
%17 = bitcast i8* %0 to i32*
store i32 %16, i32* %17
%18 = icmp slt i32 %2, 126
br i1 %18, label %44, label %19
19: ; preds = %7
%20 = icmp ult i32 %2, 65536
%21 = getelementptr inbounds i8, i8* %0, i64 4
%22 = bitcast i8* %21 to i32*
br i1 %20, label %23, label %25
23: ; preds = %19
store i32 126, i32* %22
%24 = lshr i32 %2, 8
br label %35
25: ; preds = %19
store i32 127, i32* %22
%26 = lshr i32 %2, 24
%27 = getelementptr inbounds i8, i8* %0, i64 24
%28 = bitcast i8* %27 to i32*
store i32 %26, i32* %28
%29 = lshr i32 %2, 16
%30 = and i32 %29, 255
%31 = getelementptr inbounds i8, i8* %0, i64 28
%32 = bitcast i8* %31 to i32*
store i32 %30, i32* %32
%33 = lshr i32 %2, 8
%34 = and i32 %33, 255
br label %35
35: ; preds = %23, %25
%36 = phi i64 [ 32, %25 ], [ 8, %23 ]
%37 = phi i32 [ %34, %25 ], [ %24, %23 ]
%38 = phi i64 [ 36, %25 ], [ 12, %23 ]
%39 = phi i64 [ 40, %25 ], [ 16, %23 ]
%40 = phi i32 [ 10, %25 ], [ 4, %23 ]
%41 = getelementptr inbounds i8, i8* %0, i64 %36
%42 = bitcast i8* %41 to i32*
store i32 %37, i32* %42
%43 = and i32 %2, 255
br label %44
44: ; preds = %35, %7
%45 = phi i64 [ 4, %7 ], [ %38, %35 ]
%46 = phi i32 [ %2, %7 ], [ %43, %35 ]
%47 = phi i64 [ 8, %7 ], [ %39, %35 ]
%48 = phi i32 [ 2, %7 ], [ %40, %35 ]
%49 = getelementptr inbounds i8, i8* %0, i64 %45
%50 = bitcast i8* %49 to i32*
store i32 %46, i32* %50
%51 = getelementptr inbounds i8, i8* %0, i64 %47
%52 = bitcast i8* %51 to i32*
%53 = tail call i32 @memcpy(i32* %52, i8* %1, i32 %2)
%54 = add nsw i32 %48, %2
ret i32 %54
}