#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 /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fwrite(unsigned char const *, int, unsigned long const,
                          int /*<<< orphan*/ *);
unsigned char *malloc(unsigned long const);
unsigned long rfi_rleencode(unsigned char *, unsigned long const,
                            unsigned char const *, unsigned long const);
int /*<<< orphan*/ *strstr(char const *, char *);
void rfi_writetrack(FILE *rfifile, const int track, const int side,
                    const float rpm, const char *encoding,
                    const unsigned char *rawtrackdata,
                    const unsigned long rawdatalength) {
  if (rfifile == NULL)
    return;
  fprintf(rfifile, "{track:%d,side:%d,rpm:%.2f,", track, side, rpm);
  if (strstr(encoding, "raw") != NULL) {
    fprintf(rfifile, "enc:\"%s\",len:%lu}", encoding, rawdatalength);
    fwrite(rawtrackdata, 1, rawdatalength, rfifile);
  } else if (strstr(encoding, "rle") != NULL) {
    unsigned long rledatalength;
    unsigned char *rledata;
    rledata = malloc(rawdatalength);
    if (rledata != NULL) {
      rledatalength =
          rfi_rleencode(rledata, rawdatalength, rawtrackdata, rawdatalength);
      fprintf(rfifile, "enc:\"%s\",len:%lu}", encoding, rledatalength);
      fwrite(rledata, 1, rledatalength, rfifile);
      free(rledata);
    } else {
      fprintf(rfifile, "enc:\"unknown\",len:0}");
    }
  } else {
    fprintf(rfifile, "enc:\"unknown\",len:0}");
  }
}


x86 assembly (clang, -O0):
<rfi_writetrack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movss  %xmm0,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1193 <rfi_writetrack+0x33>
jmp    12ba <rfi_writetrack+0x15a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe53(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1203 <rfi_writetrack+0xa3>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
jmp    12ba <rfi_writetrack+0x15a>
mov    -0x20(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     12a3 <rfi_writetrack+0x143>
mov    -0x30(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     128c <rfi_writetrack+0x12c>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <rfi_rleencode@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
jmp    129e <rfi_writetrack+0x13e>
mov    -0x8(%rbp),%rdi
lea    0xd9f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12b5 <rfi_writetrack+0x155>
mov    -0x8(%rbp),%rdi
lea    0xd88(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12ba <rfi_writetrack+0x15a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rfi_writetrack>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
je     11d7 <rfi_writetrack+0x77>
mov    %r9,%r15
mov    %r8,%r12
mov    %rcx,%r14
mov    %edx,%ecx
mov    %esi,%edx
mov    %rdi,%rbx
cvtss2sd %xmm0,%xmm0
lea    0xe77(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
lea    0xe85(%rip),%rsi
mov    %r14,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
je     11e1 <rfi_writetrack+0x81>
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1070 <fwrite@plt>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe4a(%rip),%rsi
mov    %r14,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
je     1254 <rfi_writetrack+0xf4>
mov    %r15,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     1254 <rfi_writetrack+0xf4>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
call   1040 <rfi_rleencode@plt>
mov    %rax,%r15
lea    0xe00(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %r13,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>
lea    0xddb(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1070 <fwrite@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"{track:%d,side:%d,rpm:%.2f,\00"
@.str.1 = [4 x i8] c"raw\00"
@.str.2 = [18 x i8] c"enc:\22%s\22,len:%lu}\00"
@.str.3 = [4 x i8] c"rle\00"
@.str.4 = [21 x i8] c"enc:\22unknown\22,len:0}\00"
define void @rfi_writetrack(i32* %0, i32 %1, i32 %2, float %3, i8* %4, i8* %5, i64 %6) {
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca float
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i64
%16 = alloca i8*
store i32* %0, i32** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store float %3, float* %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i64 %6, i64* %14
%17 = load i32*, i32** %8
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %7
br label %72
20: ; preds = %7
%21 = load i32*, i32** %8
%22 = load i32, i32* %9
%23 = load i32, i32* %10
%24 = load float, float* %11
%25 = fpext float %24 to double
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %23, double %25)
%27 = load i8*, i8** %12
%28 = call i32* @strstr(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %39
30: ; preds = %20
%31 = load i32*, i32** %8
%32 = load i8*, i8** %12
%33 = load i64, i64* %14
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %32, i64 %33)
%35 = load i8*, i8** %13
%36 = load i64, i64* %14
%37 = load i32*, i32** %8
%38 = call i32 @fwrite(i8* %35, i32 1, i64 %36, i32* %37)
br label %72
39: ; preds = %20
%40 = load i8*, i8** %12
%41 = call i32* @strstr(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %68
43: ; preds = %39
%44 = load i64, i64* %14
%45 = call i8* @malloc(i64 %44)
store i8* %45, i8** %16
%46 = load i8*, i8** %16
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %64
48: ; preds = %43
%49 = load i8*, i8** %16
%50 = load i64, i64* %14
%51 = load i8*, i8** %13
%52 = load i64, i64* %14
%53 = call i64 @rfi_rleencode(i8* %49, i64 %50, i8* %51, i64 %52)
store i64 %53, i64* %15
%54 = load i32*, i32** %8
%55 = load i8*, i8** %12
%56 = load i64, i64* %15
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %55, i64 %56)
%58 = load i8*, i8** %16
%59 = load i64, i64* %15
%60 = load i32*, i32** %8
%61 = call i32 @fwrite(i8* %58, i32 1, i64 %59, i32* %60)
%62 = load i8*, i8** %16
%63 = call i32 @free(i8* %62)
br label %67
64: ; preds = %43
%65 = load i32*, i32** %8
%66 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %67
67: ; preds = %64, %48
br label %71
68: ; preds = %39
%69 = load i32*, i32** %8
%70 = call i32 (i32*, i8*, ...) @fprintf(i32* %69, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %71
71: ; preds = %68, %67
br label %72
72: ; preds = %19, %71, %30
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"{track:%d,side:%d,rpm:%.2f,\00"
@.str.1 = [4 x i8] c"raw\00"
@.str.2 = [18 x i8] c"enc:\22%s\22,len:%lu}\00"
@.str.3 = [4 x i8] c"rle\00"
@.str.4 = [21 x i8] c"enc:\22unknown\22,len:0}\00"
define void @rfi_writetrack(i32* %0, i32 %1, i32 %2, float %3, i8* %4, i8* %5, i64 %6) {
%8 = icmp eq i32* %0, null
br i1 %8, label %32, label %9
9: ; preds = %7
%10 = fpext float %3 to double
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2, double %10)
%12 = tail call i32* @strstr(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %4, i64 %6)
%16 = tail call i32 @fwrite(i8* %5, i32 1, i64 %6, i32* %0)
br label %32
17: ; preds = %9
%18 = tail call i32* @strstr(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %30, label %20
20: ; preds = %17
%21 = tail call i8* @malloc(i64 %6)
%22 = icmp eq i8* %21, null
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = tail call i64 @rfi_rleencode(i8* %21, i64 %6, i8* %5, i64 %6)
%25 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %4, i64 %24)
%26 = tail call i32 @fwrite(i8* %21, i32 1, i64 %24, i32* %0)
%27 = tail call i32 @free(i8* %21)
br label %32
28: ; preds = %20
%29 = tail call i64 bitcast (i32 (i8*, i32, i64, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 20, i64 1, i32* %0)
br label %32
30: ; preds = %17
%31 = tail call i64 bitcast (i32 (i8*, i32, i64, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 20, i64 1, i32* %0)
br label %32
32: ; preds = %23, %28, %30, %7, %14
ret void
}