#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 */
unsigned int edc_computeblock(unsigned int, unsigned char *, int);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ setcounter_encode(int /*<<< orphan*/);
int /*<<< orphan*/ write_type_count(int /*<<< orphan*/ *, unsigned int,
                                    unsigned int);
unsigned in_flush(unsigned edc, unsigned type, unsigned count, FILE *in,
                  FILE *out) {
  unsigned char buf[2352];
  write_type_count(out, type, count);
  if (!type) {
    while (count) {
      unsigned b = count;
      if (b > 2352)
        b = 2352;
      fread(buf, 1, b, in);
      edc = edc_computeblock(edc, buf, b);
      fwrite(buf, 1, b, out);
      count -= b;
      setcounter_encode(ftell(in));
    }
    return edc;
  }
  while (count--) {
    switch (type) {
    case 1:
      fread(buf, 1, 2352, in);
      edc = edc_computeblock(edc, buf, 2352);
      fwrite(buf + 0x00C, 1, 0x003, out);
      fwrite(buf + 0x010, 1, 0x800, out);
      setcounter_encode(ftell(in));
      break;
    case 2:
      fread(buf, 1, 2336, in);
      edc = edc_computeblock(edc, buf, 2336);
      fwrite(buf + 0x004, 1, 0x804, out);
      setcounter_encode(ftell(in));
      break;
    case 3:
      fread(buf, 1, 2336, in);
      edc = edc_computeblock(edc, buf, 2336);
      fwrite(buf + 0x004, 1, 0x918, out);
      setcounter_encode(ftell(in));
      break;
    }
  }
  return edc;
}


x86 assembly (clang, -O0):
<in_flush>:
push   %rbp
mov    %rsp,%rbp
sub    $0x960,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <write_type_count@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1243 <in_flush+0xe3>
jmp    119a <in_flush+0x3a>
cmpl   $0x0,-0x10(%rbp)
je     1238 <in_flush+0xd8>
mov    -0x10(%rbp),%eax
mov    %eax,-0x954(%rbp)
cmpl   $0x930,-0x954(%rbp)
jbe    11c7 <in_flush+0x67>
movl   $0x930,-0x954(%rbp)
lea    -0x950(%rbp),%rdi
mov    -0x954(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x8(%rbp),%edi
lea    -0x950(%rbp),%rsi
mov    -0x954(%rbp),%edx
call   1060 <edc_computeblock@plt>
mov    %eax,-0x8(%rbp)
lea    -0x950(%rbp),%rdi
mov    -0x954(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
mov    -0x954(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,%edi
call   1070 <setcounter_encode@plt>
jmp    119a <in_flush+0x3a>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13eb <in_flush+0x28b>
jmp    1248 <in_flush+0xe8>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
cmp    $0x0,%eax
je     13e5 <in_flush+0x285>
mov    -0xc(%rbp),%eax
mov    %eax,-0x958(%rbp)
sub    $0x1,%eax
je     129b <in_flush+0x13b>
jmp    1273 <in_flush+0x113>
mov    -0x958(%rbp),%eax
sub    $0x2,%eax
je     131d <in_flush+0x1bd>
jmp    1287 <in_flush+0x127>
mov    -0x958(%rbp),%eax
sub    $0x3,%eax
je     1381 <in_flush+0x221>
jmp    13e0 <in_flush+0x280>
lea    -0x950(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x930,%edx
call   1030 <fread@plt>
mov    -0x8(%rbp),%edi
lea    -0x950(%rbp),%rsi
mov    $0x930,%edx
call   1060 <edc_computeblock@plt>
mov    %eax,-0x8(%rbp)
lea    -0x950(%rbp),%rdi
add    $0xc,%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   1080 <fwrite@plt>
lea    -0x950(%rbp),%rdi
add    $0x10,%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x800,%edx
call   1080 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,%edi
call   1070 <setcounter_encode@plt>
jmp    13e0 <in_flush+0x280>
lea    -0x950(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x920,%edx
call   1030 <fread@plt>
mov    -0x8(%rbp),%edi
lea    -0x950(%rbp),%rsi
mov    $0x920,%edx
call   1060 <edc_computeblock@plt>
mov    %eax,-0x8(%rbp)
lea    -0x950(%rbp),%rdi
add    $0x4,%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x804,%edx
call   1080 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,%edi
call   1070 <setcounter_encode@plt>
jmp    13e0 <in_flush+0x280>
lea    -0x950(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x920,%edx
call   1030 <fread@plt>
mov    -0x8(%rbp),%edi
lea    -0x950(%rbp),%rsi
mov    $0x920,%edx
call   1060 <edc_computeblock@plt>
mov    %eax,-0x8(%rbp)
lea    -0x950(%rbp),%rdi
add    $0x4,%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x918,%edx
call   1080 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,%edi
call   1070 <setcounter_encode@plt>
jmp    1248 <in_flush+0xe8>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x960,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<in_flush>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x938,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %edx,%ebp
mov    %esi,%r12d
mov    %edi,%r13d
mov    %r8,%rdi
call   1040 <write_type_count@plt>
test   %r12d,%r12d
je     129c <in_flush+0x13c>
test   %ebp,%ebp
je     1305 <in_flush+0x1a5>
mov    %rsp,%rbx
jmp    11f6 <in_flush+0x96>
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x920,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x920,%edx
call   1060 <edc_computeblock@plt>
mov    %eax,%r13d
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x918,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
mov    %r15,%rdi
call   1050 <ftell@plt>
mov    %eax,%edi
call   1070 <setcounter_encode@plt>
test   %ebp,%ebp
je     1305 <in_flush+0x1a5>
add    $0xffffffff,%ebp
cmp    $0x3,%r12d
je     11a0 <in_flush+0x40>
cmp    $0x2,%r12d
je     1260 <in_flush+0x100>
cmp    $0x1,%r12d
jne    11ee <in_flush+0x8e>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x930,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x930,%edx
call   1060 <edc_computeblock@plt>
mov    %eax,%r13d
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x800,%edx
jmp    11d7 <in_flush+0x77>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x920,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x920,%edx
call   1060 <edc_computeblock@plt>
mov    %eax,%r13d
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x804,%edx
jmp    11d7 <in_flush+0x77>
test   %ebp,%ebp
je     1305 <in_flush+0x1a5>
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x930,%ebp
mov    $0x930,%ebx
cmovb  %ebp,%ebx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    %ebx,%edx
call   1060 <edc_computeblock@plt>
mov    %eax,%r13d
mov    %r12,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
mov    %r15,%rdi
call   1050 <ftell@plt>
mov    %eax,%edi
call   1070 <setcounter_encode@plt>
sub    %ebx,%ebp
jne    12b0 <in_flush+0x150>
mov    %r13d,%eax
add    $0x938,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @in_flush(i32 %0, i32 %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca [2352 x i8]
%13 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store i32* %4, i32** %11
%14 = load i32*, i32** %11
%15 = load i32, i32* %8
%16 = load i32, i32* %9
%17 = call i32 @write_type_count(i32* %14, i32 %15, i32 %16)
%18 = load i32, i32* %8
%19 = icmp ne i32 %18, 0
br i1 %19, label %50, label %20
20: ; preds = %5
br label %21
21: ; preds = %29, %20
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %48
24: ; preds = %21
%25 = load i32, i32* %9
store i32 %25, i32* %13
%26 = load i32, i32* %13
%27 = icmp ugt i32 %26, 2352
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 2352, i32* %13
br label %29
29: ; preds = %28, %24
%30 = getelementptr inbounds [2352 x i8], [2352 x i8]* %12, i64 0, i64 0
%31 = load i32, i32* %13
%32 = load i32*, i32** %10
%33 = call i32 @fread(i8* %30, i32 1, i32 %31, i32* %32)
%34 = load i32, i32* %7
%35 = getelementptr inbounds [2352 x i8], [2352 x i8]* %12, i64 0, i64 0
%36 = load i32, i32* %13
%37 = call i32 @edc_computeblock(i32 %34, i8* %35, i32 %36)
store i32 %37, i32* %7
%38 = getelementptr inbounds [2352 x i8], [2352 x i8]* %12, i64 0, i64 0
%39 = load i32, i32* %13
%40 = load i32*, i32** %11
%41 = call i32 @fwrite(i8* %38, i32 1, i32 %39, i32* %40)
%42 = load i32, i32* %13
%43 = load i32, i32* %9
%44 = sub i32 %43, %42
store i32 %44, i32* %9
%45 = load i32*, i32** %10
%46 = call i32 @ftell(i32* %45)
%47 = call i32 @setcounter_encode(i32 %46)
br label %21
48: ; preds = %21
%49 = load i32, i32* %7
store i32 %49, i32* %6
br label %106
50: ; preds = %5
br label %51
51: ; preds = %103, %50
%52 = load i32, i32* %9
%53 = add i32 %52, -1
store i32 %53, i32* %9
%54 = icmp ne i32 %52, 0
br i1 %54, label %55, label %104
55: ; preds = %51
%56 = load i32, i32* %8
switch i32 %56, label %103 [
i32 1, label %57
i32 2, label %75
i32 3, label %89
]
57: ; preds = %55
%58 = getelementptr inbounds [2352 x i8], [2352 x i8]* %12, i64 0, i64 0
%59 = load i32*, i32** %10
%60 = call i32 @fread(i8* %58, i32 1, i32 2352, i32* %59)
%61 = load i32, i32* %7
%62 = getelementptr inbounds [2352 x i8], [2352 x i8]* %12, i64 0, i64 0
%63 = call i32 @edc_computeblock(i32 %61, i8* %62, i32 2352)
store i32 %63, i32* %7
%64 = getelementptr inbounds [2352 x i8], [2352 x i8]* %12, i64 0, i64 0
%65 = getelementptr inbounds i8, i8* %64, i64 12
%66 = load i32*, i32** %11
%67 = call i32 @fwrite(i8* %65, i32 1, i32 3, i32* %66)
%68 = getelementptr inbounds [2352 x i8], [2352 x i8]* %12, i64 0, i64 0
%69 = getelementptr inbounds i8, i8* %68, i64 16
%70 = load i32*, i32** %11
%71 = call i32 @fwrite(i8* %69, i32 1, i32 2048, i32* %70)
%72 = load i32*, i32** %10
%73 = call i32 @ftell(i32* %72)
%74 = call i32 @setcounter_encode(i32 %73)
br label %103
75: ; preds = %55
%76 = getelementptr inbounds [2352 x i8], [2352 x i8]* %12, i64 0, i64 0
%77 = load i32*, i32** %10
%78 = call i32 @fread(i8* %76, i32 1, i32 2336, i32* %77)
%79 = load i32, i32* %7
%80 = getelementptr inbounds [2352 x i8], [2352 x i8]* %12, i64 0, i64 0
%81 = call i32 @edc_computeblock(i32 %79, i8* %80, i32 2336)
store i32 %81, i32* %7
%82 = getelementptr inbounds [2352 x i8], [2352 x i8]* %12, i64 0, i64 0
%83 = getelementptr inbounds i8, i8* %82, i64 4
%84 = load i32*, i32** %11
%85 = call i32 @fwrite(i8* %83, i32 1, i32 2052, i32* %84)
%86 = load i32*, i32** %10
%87 = call i32 @ftell(i32* %86)
%88 = call i32 @setcounter_encode(i32 %87)
br label %103
89: ; preds = %55
%90 = getelementptr inbounds [2352 x i8], [2352 x i8]* %12, i64 0, i64 0
%91 = load i32*, i32** %10
%92 = call i32 @fread(i8* %90, i32 1, i32 2336, i32* %91)
%93 = load i32, i32* %7
%94 = getelementptr inbounds [2352 x i8], [2352 x i8]* %12, i64 0, i64 0
%95 = call i32 @edc_computeblock(i32 %93, i8* %94, i32 2336)
store i32 %95, i32* %7
%96 = getelementptr inbounds [2352 x i8], [2352 x i8]* %12, i64 0, i64 0
%97 = getelementptr inbounds i8, i8* %96, i64 4
%98 = load i32*, i32** %11
%99 = call i32 @fwrite(i8* %97, i32 1, i32 2328, i32* %98)
%100 = load i32*, i32** %10
%101 = call i32 @ftell(i32* %100)
%102 = call i32 @setcounter_encode(i32 %101)
br label %103
103: ; preds = %55, %89, %75, %57
br label %51
104: ; preds = %51
%105 = load i32, i32* %7
store i32 %105, i32* %6
br label %106
106: ; preds = %104, %48
%107 = load i32, i32* %6
ret i32 %107
}

LLVM IR (-O2):
define i32 @in_flush(i32 %0, i32 %1, i32 %2, i32* nocapture %3, i32* %4) {
%6 = alloca [2352 x i8]
%7 = getelementptr inbounds [2352 x i8], [2352 x i8]* %6, i64 0, i64 0
%8 = tail call i32 @write_type_count(i32* %4, i32 %1, i32 %2)
%9 = icmp eq i32 %1, 0
%10 = icmp eq i32 %2, 0
br i1 %9, label %16, label %11
11: ; preds = %5
br i1 %10, label %53, label %12
12: ; preds = %11
%13 = getelementptr inbounds [2352 x i8], [2352 x i8]* %6, i64 0, i64 4
%14 = getelementptr inbounds [2352 x i8], [2352 x i8]* %6, i64 0, i64 12
%15 = getelementptr inbounds [2352 x i8], [2352 x i8]* %6, i64 0, i64 16
br label %29
16: ; preds = %5
br i1 %10, label %53, label %17
17: ; preds = %16, %17
%18 = phi i32 [ %23, %17 ], [ %0, %16 ]
%19 = phi i32 [ %25, %17 ], [ %2, %16 ]
%20 = icmp ult i32 %19, 2352
%21 = select i1 %20, i32 %19, i32 2352
%22 = call i32 @fread(i8* %7, i32 1, i32 %21, i32* %3)
%23 = call i32 @edc_computeblock(i32 %18, i8* %7, i32 %21)
%24 = call i32 @fwrite(i8* %7, i32 1, i32 %21, i32* %4)
%25 = sub i32 %19, %21
%26 = call i32 @ftell(i32* %3)
%27 = call i32 @setcounter_encode(i32 %26)
%28 = icmp eq i32 %25, 0
br i1 %28, label %53, label %17
29: ; preds = %12, %50
%30 = phi i32 [ %2, %12 ], [ %32, %50 ]
%31 = phi i32 [ %0, %12 ], [ %51, %50 ]
%32 = add i32 %30, -1
switch i32 %1, label %50 [
i32 1, label %33
i32 2, label %38
i32 3, label %42
]
33: ; preds = %29
%34 = call i32 @fread(i8* %7, i32 1, i32 2352, i32* %3)
%35 = call i32 @edc_computeblock(i32 %31, i8* %7, i32 2352)
%36 = call i32 @fwrite(i8* %14, i32 1, i32 3, i32* %4)
%37 = call i32 @fwrite(i8* %15, i32 1, i32 2048, i32* %4)
br label %46
38: ; preds = %29
%39 = call i32 @fread(i8* %7, i32 1, i32 2336, i32* %3)
%40 = call i32 @edc_computeblock(i32 %31, i8* %7, i32 2336)
%41 = call i32 @fwrite(i8* %13, i32 1, i32 2052, i32* %4)
br label %46
42: ; preds = %29
%43 = call i32 @fread(i8* %7, i32 1, i32 2336, i32* %3)
%44 = call i32 @edc_computeblock(i32 %31, i8* %7, i32 2336)
%45 = call i32 @fwrite(i8* %13, i32 1, i32 2328, i32* %4)
br label %46
46: ; preds = %33, %38, %42
%47 = phi i32 [ %35, %33 ], [ %40, %38 ], [ %44, %42 ]
%48 = call i32 @ftell(i32* %3)
%49 = call i32 @setcounter_encode(i32 %48)
br label %50
50: ; preds = %46, %29
%51 = phi i32 [ %31, %29 ], [ %47, %46 ]
%52 = icmp eq i32 %32, 0
br i1 %52, label %53, label %29
53: ; preds = %50, %17, %11, %16
%54 = phi i32 [ %0, %16 ], [ %0, %11 ], [ %23, %17 ], [ %51, %50 ]
ret i32 %54
}