#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 sendReceiveCmd(int, unsigned char *, int, unsigned char *, int);
OpenChannel(int fd, unsigned char sockId, int *sndSz, int *rcvSz) {
  unsigned char cmd[17];
  unsigned char buf[20];
  int rd;
  for (;;) {
    cmd[0] = 0;
    cmd[1] = 0;
    cmd[2] = 0;
    cmd[3] = 17;
    cmd[4] = 1;
    cmd[5] = 0;
    cmd[6] = 1;
    cmd[7] = sockId;
    cmd[8] = sockId;
    cmd[9] = *sndSz >> 8;
    cmd[10] = *sndSz & 0xff;
    cmd[11] = *rcvSz >> 8;
    cmd[12] = *rcvSz & 0xff;
    cmd[13] = 0;
    cmd[14] = 0;
    cmd[15] = 0;
    cmd[16] = 0;
    rd = sendReceiveCmd(fd, cmd, 17, buf, 16);
    if (rd == -1) {
      return -1;
    } else if (rd == 16) {
      if (buf[7] == 4) {
        continue;
      } else if (buf[7] != 0) {
        return -1;
      }
      *sndSz = (buf[10] << 8) + buf[11];
      *rcvSz = (buf[12] << 8) + buf[13];
      break;
    } else {
      return -1;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<OpenChannel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movb   $0x0,-0x40(%rbp)
movb   $0x0,-0x3f(%rbp)
movb   $0x0,-0x3e(%rbp)
movb   $0x11,-0x3d(%rbp)
movb   $0x1,-0x3c(%rbp)
movb   $0x0,-0x3b(%rbp)
movb   $0x1,-0x3a(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x39(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
sar    $0x8,%eax
mov    %al,-0x37(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
and    $0xff,%eax
mov    %al,-0x36(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
sar    $0x8,%eax
mov    %al,-0x35(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
and    $0xff,%eax
mov    %al,-0x34(%rbp)
movb   $0x0,-0x33(%rbp)
movb   $0x0,-0x32(%rbp)
movb   $0x0,-0x31(%rbp)
movb   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x60(%rbp),%rcx
mov    $0x11,%edx
mov    $0x10,%r8d
call   1030 <sendReceiveCmd@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    11c9 <OpenChannel+0xb9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <OpenChannel+0x131>
cmpl   $0x10,-0x64(%rbp)
jne    122e <OpenChannel+0x11e>
movzbl -0x59(%rbp),%eax
cmp    $0x4,%eax
jne    11e5 <OpenChannel+0xd5>
jmp    1129 <OpenChannel+0x19>
movzbl -0x59(%rbp),%eax
cmp    $0x0,%eax
je     11fe <OpenChannel+0xee>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <OpenChannel+0x131>
jmp    1203 <OpenChannel+0xf3>
movzbl -0x56(%rbp),%ecx
shl    $0x8,%ecx
movzbl -0x55(%rbp),%eax
add    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movzbl -0x54(%rbp),%ecx
shl    $0x8,%ecx
movzbl -0x53(%rbp),%eax
add    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    123a <OpenChannel+0x12a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <OpenChannel+0x131>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OpenChannel>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%r12
lea    0x20(%rsp),%r13
movl   $0x11000000,(%rsp)
movw   $0x1,0x4(%rsp)
movb   $0x1,0x6(%rsp)
mov    %bpl,0x7(%rsp)
mov    %bpl,0x8(%rsp)
movzwl (%r15),%eax
rol    $0x8,%ax
mov    %ax,0x9(%rsp)
mov    (%r14),%eax
mov    %ah,0xb(%rsp)
mov    %al,0xc(%rsp)
movl   $0x0,0xd(%rsp)
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x11,%edx
mov    %r13,%rcx
mov    $0x10,%r8d
call   1030 <sendReceiveCmd@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x10,%ecx
jne    11be <OpenChannel+0xae>
movzbl 0x27(%rsp),%ecx
cmp    $0x4,%cl
je     1130 <OpenChannel+0x20>
test   %cl,%cl
jne    11be <OpenChannel+0xae>
movzwl 0x2a(%rsp),%eax
shl    $0x10,%eax
bswap  %eax
mov    %eax,(%r15)
movzwl 0x2c(%rsp),%eax
shl    $0x10,%eax
bswap  %eax
mov    %eax,(%r14)
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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