#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 /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ write_bits(int /*<<< orphan*/ *, int, int, int *);
long write_byte(FILE *out, unsigned char b, int *sync) {
  int a;
  long flen = 0;
  for (a = 0; a < 8; a++) {
    if (b & (1 << a))
      flen += write_bits(out, (1200), 1, sync);
    else
      flen += write_bits(out, (2400), 1, sync);
  }
  flen += write_bits(out, (600), 1, sync);
  return flen;
}


x86 assembly (clang, -O0):
<write_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    11b0 <write_byte+0xa0>
movzbl -0x9(%rbp),%eax
mov    -0x1c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     117e <write_byte+0x6e>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4b0,%esi
mov    $0x1,%edx
call   1030 <write_bits@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    119d <write_byte+0x8d>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x960,%esi
mov    $0x1,%edx
call   1030 <write_bits@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11a2 <write_byte+0x92>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1135 <write_byte+0x25>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x258,%esi
mov    $0x1,%edx
call   1030 <write_bits@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_byte>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rdi,%r12
movd   %esi,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xecb(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xecf(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%ebx
test   $0x80,%bl
mov    $0x960,%r15d
mov    $0x4b0,%esi
cmovne %r15d,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <write_bits@plt>
mov    %rax,0x20(%rsp)
test   $0x40,%bl
mov    $0x4b0,%esi
cmovne %r15d,%esi
mov    %r12,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <write_bits@plt>
mov    %rax,%rbp
test   $0x20,%bl
mov    $0x4b0,%esi
cmovne %r15d,%esi
mov    %r12,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <write_bits@plt>
mov    %rax,0x18(%rsp)
test   $0x10,%bl
mov    $0x4b0,%esi
cmovne %r15d,%esi
mov    %r12,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <write_bits@plt>
mov    %rax,0x10(%rsp)
test   $0x8,%bl
mov    $0x4b0,%esi
cmovne %r15d,%esi
mov    %r12,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <write_bits@plt>
mov    %rax,0x8(%rsp)
test   $0x4,%bl
mov    $0x4b0,%esi
cmovne %r15d,%esi
mov    %r12,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <write_bits@plt>
mov    %rax,(%rsp)
test   $0x2,%bl
mov    $0x4b0,%esi
cmovne %r15d,%esi
mov    %r12,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <write_bits@plt>
mov    %rax,%r13
test   $0x1,%bl
mov    $0x4b0,%esi
cmovne %r15d,%esi
mov    %r12,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <write_bits@plt>
mov    %rax,%rbx
add    0x20(%rsp),%rbp
add    0x18(%rsp),%rbp
add    0x10(%rsp),%rbp
add    0x8(%rsp),%rbp
add    (%rsp),%rbp
add    %r13,%rbp
add    %rbp,%rbx
mov    %r12,%rdi
mov    $0x258,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <write_bits@plt>
add    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @write_byte(i32* %0, i8 zeroext %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i8
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i64
store i32* %0, i32** %4
store i8 %1, i8* %5
store i32* %2, i32** %6
store i64 0, i64* %8
store i32 0, i32* %7
br label %9
9: ; preds = %32, %3
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 8
br i1 %11, label %12, label %35
12: ; preds = %9
%13 = load i8, i8* %5
%14 = zext i8 %13 to i32
%15 = load i32, i32* %7
%16 = shl i32 1, %15
%17 = and i32 %14, %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %12
%20 = load i32*, i32** %4
%21 = load i32*, i32** %6
%22 = call i64 @write_bits(i32* %20, i32 1200, i32 1, i32* %21)
%23 = load i64, i64* %8
%24 = add nsw i64 %23, %22
store i64 %24, i64* %8
br label %31
25: ; preds = %12
%26 = load i32*, i32** %4
%27 = load i32*, i32** %6
%28 = call i64 @write_bits(i32* %26, i32 2400, i32 1, i32* %27)
%29 = load i64, i64* %8
%30 = add nsw i64 %29, %28
store i64 %30, i64* %8
br label %31
31: ; preds = %25, %19
br label %32
32: ; preds = %31
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %9
35: ; preds = %9
%36 = load i32*, i32** %4
%37 = load i32*, i32** %6
%38 = call i64 @write_bits(i32* %36, i32 600, i32 1, i32* %37)
%39 = load i64, i64* %8
%40 = add nsw i64 %39, %38
store i64 %40, i64* %8
%41 = load i64, i64* %8
ret i64 %41
}

LLVM IR (-O2):
define i64 @write_byte(i32* %0, i8 zeroext %1, i32* %2) {
%4 = zext i8 %1 to i32
%5 = insertelement <8 x i32> poison, i32 %4, i64 0
%6 = shufflevector <8 x i32> %5, <8 x i32> poison, <8 x i32> zeroinitializer
%7 = and <8 x i32> %6, <i32 128, i32 64, i32 32, i32 16, i32 8, i32 4, i32 2, i32 1>
%8 = icmp eq <8 x i32> %7, zeroinitializer
%9 = extractelement <8 x i1> %8, i64 7
%10 = select i1 %9, i32 2400, i32 1200
%11 = tail call i64 @write_bits(i32* %0, i32 %10, i32 1, i32* %2)
%12 = extractelement <8 x i1> %8, i64 6
%13 = select i1 %12, i32 2400, i32 1200
%14 = tail call i64 @write_bits(i32* %0, i32 %13, i32 1, i32* %2)
%15 = extractelement <8 x i1> %8, i64 5
%16 = select i1 %15, i32 2400, i32 1200
%17 = tail call i64 @write_bits(i32* %0, i32 %16, i32 1, i32* %2)
%18 = extractelement <8 x i1> %8, i64 4
%19 = select i1 %18, i32 2400, i32 1200
%20 = tail call i64 @write_bits(i32* %0, i32 %19, i32 1, i32* %2)
%21 = extractelement <8 x i1> %8, i64 3
%22 = select i1 %21, i32 2400, i32 1200
%23 = tail call i64 @write_bits(i32* %0, i32 %22, i32 1, i32* %2)
%24 = extractelement <8 x i1> %8, i64 2
%25 = select i1 %24, i32 2400, i32 1200
%26 = tail call i64 @write_bits(i32* %0, i32 %25, i32 1, i32* %2)
%27 = extractelement <8 x i1> %8, i64 1
%28 = select i1 %27, i32 2400, i32 1200
%29 = tail call i64 @write_bits(i32* %0, i32 %28, i32 1, i32* %2)
%30 = extractelement <8 x i1> %8, i64 0
%31 = select i1 %30, i32 2400, i32 1200
%32 = tail call i64 @write_bits(i32* %0, i32 %31, i32 1, i32* %2)
%33 = add nsw i64 %14, %11
%34 = add nsw i64 %17, %33
%35 = add nsw i64 %20, %34
%36 = add nsw i64 %23, %35
%37 = add nsw i64 %26, %36
%38 = add nsw i64 %29, %37
%39 = add nsw i64 %32, %38
%40 = tail call i64 @write_bits(i32* %0, i32 600, i32 1, i32* %2)
%41 = add nsw i64 %40, %39
ret i64 %41
}