#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 uint16_t;

/* Variables and functions */
int /*<<< orphan*/ byte_to_binary(int);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ word_to_binary(int);
int main(int argc, char **argv) {
  int i;
  uint16_t msgWord;
  char bMSB[9];
  char bLSB[9];
  char bWord[17];
  uint8_t input[16] = {
      0b00001101, 0b11011100, 0b00010101, 0b11100001, 0b00011101, 0b11010111,
      0b00100100, 0b00010110, 0b00101010, 0b11001001, 0b00110010, 0b01010010,
      0b00111100, 0b00100100, 0b01000111, 0b11111111,
  };
  for (i = 0; i < 16; i += 2) {
    strncpy(bMSB, byte_to_binary(input[i]), 9);
    strncpy(bLSB, byte_to_binary(input[i + 1]), 9);
    printf("MSB: %4.4hx %s LSB: %4.4hx %s\n", input[i], bMSB, input[i + 1],
           bLSB);
    uint16_t msgWord = input[i] << 8;
    msgWord = msgWord | input[i + 1];
    strncpy(bWord, word_to_binary(msgWord), 17);
    printf("msgWord: %4.4hx %s\n", msgWord, bWord);
    int channelNum = (msgWord & 0x7800) >> 11;
    int channelVal = msgWord & 0x07FF;
    printf("CHAN: %4d VAL: %4d\n\n", channelNum, channelVal);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xe8c(%rip),%rsi
mov    $0x40,%edx
call   1070 <memcpy@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    12cb <main+0x17b>
lea    -0x21(%rbp),%rax
mov    %rax,-0xa8(%rbp)
movslq -0x14(%rbp),%rax
mov    -0x80(%rbp,%rax,4),%edi
call   1040 <byte_to_binary@plt>
mov    -0xa8(%rbp),%rdi
mov    %eax,%esi
mov    $0x9,%edx
call   1030 <strncpy@plt>
lea    -0x2a(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x80(%rbp,%rax,4),%edi
call   1040 <byte_to_binary@plt>
mov    -0xa0(%rbp),%rdi
mov    %eax,%esi
mov    $0x9,%edx
call   1030 <strncpy@plt>
movslq -0x14(%rbp),%rax
mov    -0x80(%rbp,%rax,4),%esi
lea    -0x21(%rbp),%rdx
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x80(%rbp,%rax,4),%ecx
lea    -0x2a(%rbp),%r8
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x14(%rbp),%rax
mov    -0x80(%rbp,%rax,4),%eax
shl    $0x8,%eax
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
or     -0x80(%rbp,%rcx,4),%eax
mov    %eax,-0x84(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x84(%rbp),%edi
call   1060 <word_to_binary@plt>
mov    -0x98(%rbp),%rdi
mov    %eax,%esi
mov    $0x11,%edx
call   1030 <strncpy@plt>
mov    -0x84(%rbp),%esi
lea    -0x40(%rbp),%rdx
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x84(%rbp),%eax
and    $0x7800,%eax
sar    $0xb,%eax
mov    %eax,-0x88(%rbp)
mov    -0x84(%rbp),%eax
and    $0x7ff,%eax
mov    %eax,-0x8c(%rbp)
mov    -0x88(%rbp),%esi
mov    -0x8c(%rbp),%edx
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1185 <main+0x35>
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    $0xfffffffffffffffe,%rbp
lea    0x17(%rsp),%r14
lea    0xe(%rsp),%r12
lea    0x20(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe89(%rip),%rax
mov    0x8(%rax,%rbp,4),%r15d
mov    0xc(%rax,%rbp,4),%r13d
mov    %r15d,%edi
call   1040 <byte_to_binary@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x9,%edx
call   1030 <strncpy@plt>
mov    %r13d,%edi
call   1040 <byte_to_binary@plt>
mov    %r12,%rdi
mov    %eax,%esi
mov    $0x9,%edx
call   1030 <strncpy@plt>
lea    0xe8a(%rip),%rdi
mov    %r15d,%esi
mov    %r14,%rdx
mov    %r13d,%ecx
mov    %r12,%r8
xor    %eax,%eax
call   1050 <printf@plt>
shl    $0x8,%r15d
or     %r13d,%r15d
mov    %r15d,%edi
call   1060 <word_to_binary@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x11,%edx
call   1030 <strncpy@plt>
lea    0xe71(%rip),%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%esi
shr    $0xb,%esi
and    $0xf,%esi
and    $0x7ff,%r15d
lea    0xe61(%rip),%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x2,%rbp
cmp    $0xe,%rbp
jb     1170 <main+0x30>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.input = [16 x i32] [i32 13, i32 220, i32 21, i32 225, i32 29, i32 215, i32 36, i32 22, i32 42, i32 201, i32 50, i32 82, i32 60, i32 36, i32 71, i32 255]
@.str = [31 x i8] c"MSB: %4.4hx %s LSB: %4.4hx %s\0A\00"
@.str.1 = [20 x i8] c"msgWord: %4.4hx %s\0A\00"
@.str.2 = [21 x i8] c"CHAN: %4d VAL: %4d\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [9 x i8]
%9 = alloca [9 x i8]
%10 = alloca [17 x i8]
%11 = alloca [16 x i32]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = bitcast [16 x i32]* %11 to i8*
store i32 0, i32* %6
br label %16
16: ; preds = %74, %2
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 16
br i1 %18, label %19, label %77
19: ; preds = %16
%20 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = call i32 @byte_to_binary(i32 %24)
%26 = call i32 @strncpy(i8* %20, i32 %25, i32 9)
%27 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 0
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = call i32 @byte_to_binary(i32 %32)
%34 = call i32 @strncpy(i8* %27, i32 %33, i32 9)
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 0
%46 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %38, i8* %39, i32 %44, i8* %45)
%47 = load i32, i32* %6
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = shl i32 %50, 8
store i32 %51, i32* %12
%52 = load i32, i32* %12
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [16 x i32], [16 x i32]* %11, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = or i32 %52, %57
store i32 %58, i32* %12
%59 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 0
%60 = load i32, i32* %12
%61 = call i32 @word_to_binary(i32 %60)
%62 = call i32 @strncpy(i8* %59, i32 %61, i32 17)
%63 = load i32, i32* %12
%64 = getelementptr inbounds [17 x i8], [17 x i8]* %10, i64 0, i64 0
%65 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %63, i8* %64)
%66 = load i32, i32* %12
%67 = and i32 %66, 30720
%68 = ashr i32 %67, 11
store i32 %68, i32* %13
%69 = load i32, i32* %12
%70 = and i32 %69, 2047
store i32 %70, i32* %14
%71 = load i32, i32* %13
%72 = load i32, i32* %14
%73 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %71, i32 %72)
br label %74
74: ; preds = %19
%75 = load i32, i32* %6
%76 = add nsw i32 %75, 2
store i32 %76, i32* %6
br label %16
77: ; preds = %16
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@__const.main.input = [16 x i32] [i32 13, i32 220, i32 21, i32 225, i32 29, i32 215, i32 36, i32 22, i32 42, i32 201, i32 50, i32 82, i32 60, i32 36, i32 71, i32 255]
@.str = [31 x i8] c"MSB: %4.4hx %s LSB: %4.4hx %s\0A\00"
@.str.1 = [20 x i8] c"msgWord: %4.4hx %s\0A\00"
@.str.2 = [21 x i8] c"CHAN: %4d VAL: %4d\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [9 x i8]
%4 = alloca [9 x i8]
%5 = alloca [17 x i8]
%6 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
br label %9
9: ; preds = %2, %9
%10 = phi i64 [ 0, %2 ], [ %30, %9 ]
%11 = getelementptr inbounds [16 x i32], [16 x i32]* @__const.main.input, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = call i32 @byte_to_binary(i32 %12)
%14 = call i32 @strncpy(i8* %6, i32 %13, i32 9)
%15 = or i64 %10, 1
%16 = getelementptr inbounds [16 x i32], [16 x i32]* @__const.main.input, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = call i32 @byte_to_binary(i32 %17)
%19 = call i32 @strncpy(i8* %7, i32 %18, i32 9)
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %6, i32 %17, i8* %7)
%21 = shl i32 %12, 8
%22 = or i32 %17, %21
%23 = call i32 @word_to_binary(i32 %22)
%24 = call i32 @strncpy(i8* %8, i32 %23, i32 17)
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %22, i8* %8)
%26 = lshr i32 %22, 11
%27 = and i32 %26, 15
%28 = and i32 %22, 2047
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %28)
%30 = add nuw nsw i64 %10, 2
%31 = icmp ult i64 %10, 14
br i1 %31, label %9, label %32
32: ; preds = %9
ret i32 0
}