#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, ...);
int tap_writepulse(FILE *file, long len) {
  int n = len / 8 ?: 1;
  if (n > 255) {
    fprintf(file, "%c%c%c%c", 0, n & 0xff, (n >> 8) & 0xff, (n >> 16) & 0xff);
    return 4;
  } else {
    fprintf(file, "%c", n & 0xff);
    return 1;
  }
}


x86 assembly (clang, -O0):
<tap_writepulse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1149 <tap_writepulse+0x39>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1157 <tap_writepulse+0x47>
mov    $0x1,%eax
mov    %rax,-0x30(%rbp)
jmp    1157 <tap_writepulse+0x47>
mov    -0x30(%rbp),%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0xff,-0x1c(%rbp)
jle    11b2 <tap_writepulse+0xa2>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
and    $0xff,%ecx
mov    -0x1c(%rbp),%r8d
sar    $0x8,%r8d
and    $0xff,%r8d
mov    -0x1c(%rbp),%r9d
sar    $0x10,%r9d
and    $0xff,%r9d
lea    0xe63(%rip),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x4,-0x4(%rbp)
jmp    11d4 <tap_writepulse+0xc4>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
and    $0xff,%edx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tap_writepulse>:
push   %rbx
mov    %rsi,%rdx
lea    0x7(%rsi),%rcx
test   %rsi,%rsi
cmovs  %rcx,%rdx
mov    %rdi,%rax
shr    $0x3,%rdx
cmp    $0xf,%rcx
mov    $0x1,%ebx
cmovb  %ebx,%edx
movzbl %dl,%ecx
cmp    $0x100,%edx
jl     1174 <tap_writepulse+0x54>
movzbl %dh,%ebx
shr    $0x10,%edx
movzbl %dl,%r9d
lea    0xea2(%rip),%rsi
mov    %rax,%rdi
xor    %edx,%edx
mov    %ebx,%r8d
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x4,%ebx
jmp    117e <tap_writepulse+0x5e>
mov    %ecx,%edi
mov    %rax,%rsi
call   1030 <fputc@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%c%c%c%c\00"
@.str.1 = [3 x i8] c"%c\00"
define i32 @tap_writepulse(i32* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32
store i32* %0, i32** %4
store i64 %1, i64* %5
%7 = load i64, i64* %5
%8 = sdiv i64 %7, 8
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
br label %12
11: ; preds = %2
br label %12
12: ; preds = %11, %10
%13 = phi i64 [ %8, %10 ], [ 1, %11 ]
%14 = trunc i64 %13 to i32
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp sgt i32 %15, 255
br i1 %16, label %17, label %28
17: ; preds = %12
%18 = load i32*, i32** %4
%19 = load i32, i32* %6
%20 = and i32 %19, 255
%21 = load i32, i32* %6
%22 = ashr i32 %21, 8
%23 = and i32 %22, 255
%24 = load i32, i32* %6
%25 = ashr i32 %24, 16
%26 = and i32 %25, 255
%27 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0, i32 %20, i32 %23, i32 %26)
store i32 4, i32* %3
br label %33
28: ; preds = %12
%29 = load i32*, i32** %4
%30 = load i32, i32* %6
%31 = and i32 %30, 255
%32 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %31)
store i32 1, i32* %3
br label %33
33: ; preds = %28, %17
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [9 x i8] c"%c%c%c%c\00"
define i32 @tap_writepulse(i32* nocapture %0, i64 %1) {
%3 = sdiv i64 %1, 8
%4 = add i64 %1, 7
%5 = icmp ult i64 %4, 15
%6 = trunc i64 %3 to i32
%7 = select i1 %5, i32 1, i32 %6
%8 = icmp sgt i32 %7, 255
%9 = and i32 %7, 255
br i1 %8, label %10, label %16
10: ; preds = %2
%11 = lshr i32 %7, 8
%12 = and i32 %11, 255
%13 = lshr i32 %7, 16
%14 = and i32 %13, 255
%15 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0, i32 %9, i32 %12, i32 %14)
br label %18
16: ; preds = %2
%17 = tail call i32 @fputc(i32 %9, i32* %0)
br label %18
18: ; preds = %16, %10
%19 = phi i32 [ 4, %10 ], [ 1, %16 ]
ret i32 %19
}