#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 */

/* Variables and functions */
int /*<<< orphan*/ ecc_generate(unsigned char *, int);
int /*<<< orphan*/ edc_computeblock(unsigned char *, int, unsigned char *);
void eccedc_generate(unsigned char *sector, int type) {
  unsigned i;
  switch (type) {
  case 1:
    edc_computeblock(sector + 0x00, 0x810, sector + 0x810);
    for (i = 0; i < 8; i++)
      sector[0x814 + i] = 0;
    ecc_generate(sector, 0);
    break;
  case 2:
    edc_computeblock(sector + 0x10, 0x808, sector + 0x818);
    ecc_generate(sector, 1);
    break;
  case 3:
    edc_computeblock(sector + 0x10, 0x91C, sector + 0x92C);
    break;
  }
}


x86 assembly (clang, -O0):
<eccedc_generate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x1,%eax
je     1165 <eccedc_generate+0x45>
jmp    1143 <eccedc_generate+0x23>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     11c0 <eccedc_generate+0xa0>
jmp    1154 <eccedc_generate+0x34>
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
je     11f0 <eccedc_generate+0xd0>
jmp    120d <eccedc_generate+0xed>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
add    $0x810,%rdx
mov    $0x810,%esi
call   1030 <edc_computeblock@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jae    11b0 <eccedc_generate+0x90>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x814,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1185 <eccedc_generate+0x65>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1040 <ecc_generate@plt>
jmp    120d <eccedc_generate+0xed>
mov    -0x8(%rbp),%rdi
add    $0x10,%rdi
mov    -0x8(%rbp),%rdx
add    $0x818,%rdx
mov    $0x808,%esi
call   1030 <edc_computeblock@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1040 <ecc_generate@plt>
jmp    120d <eccedc_generate+0xed>
mov    -0x8(%rbp),%rdi
add    $0x10,%rdi
mov    -0x8(%rbp),%rdx
add    $0x92c,%rdx
mov    $0x91c,%esi
call   1030 <edc_computeblock@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eccedc_generate>:
push   %rbx
mov    %rdi,%rbx
cmp    $0x3,%esi
je     115d <eccedc_generate+0x3d>
cmp    $0x2,%esi
je     1176 <eccedc_generate+0x56>
cmp    $0x1,%esi
jne    1199 <eccedc_generate+0x79>
lea    0x810(%rbx),%rdx
mov    %rbx,%rdi
mov    $0x810,%esi
call   1030 <edc_computeblock@plt>
movq   $0x0,0x814(%rbx)
mov    %rbx,%rdi
xor    %esi,%esi
pop    %rbx
jmp    1040 <ecc_generate@plt>
lea    0x10(%rbx),%rdi
add    $0x92c,%rbx
mov    $0x91c,%esi
mov    %rbx,%rdx
pop    %rbx
jmp    1030 <edc_computeblock@plt>
lea    0x10(%rbx),%rdi
lea    0x818(%rbx),%rdx
mov    $0x808,%esi
call   1030 <edc_computeblock@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
pop    %rbx
jmp    1040 <ecc_generate@plt>
pop    %rbx
ret

LLVM IR (-O0):
define void @eccedc_generate(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
switch i32 %6, label %42 [
i32 1, label %7
i32 2, label %28
i32 3, label %36
]
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 2064
%12 = call i32 @edc_computeblock(i8* %9, i32 2064, i8* %11)
store i32 0, i32* %5
br label %13
13: ; preds = %22, %7
%14 = load i32, i32* %5
%15 = icmp ult i32 %14, 8
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = add i32 2068, %18
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
store i8 0, i8* %21
br label %22
22: ; preds = %16
%23 = load i32, i32* %5
%24 = add i32 %23, 1
store i32 %24, i32* %5
br label %13
25: ; preds = %13
%26 = load i8*, i8** %3
%27 = call i32 @ecc_generate(i8* %26, i32 0)
br label %42
28: ; preds = %2
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i64 16
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 2072
%33 = call i32 @edc_computeblock(i8* %30, i32 2056, i8* %32)
%34 = load i8*, i8** %3
%35 = call i32 @ecc_generate(i8* %34, i32 1)
br label %42
36: ; preds = %2
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i64 16
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i64 2348
%41 = call i32 @edc_computeblock(i8* %38, i32 2332, i8* %40)
br label %42
42: ; preds = %2, %36, %28, %25
ret void
}

LLVM IR (-O2):
define void @eccedc_generate(i8* %0, i32 %1) {
switch i32 %1, label %18 [
i32 1, label %3
i32 2, label %9
i32 3, label %14
]
3: ; preds = %2
%4 = getelementptr inbounds i8, i8* %0, i64 2064
%5 = tail call i32 @edc_computeblock(i8* %0, i32 2064, i8* %4)
%6 = getelementptr i8, i8* %0, i64 2068
%7 = bitcast i8* %6 to i64*
store i64 0, i64* %7
%8 = tail call i32 @ecc_generate(i8* %0, i32 0)
br label %18
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %0, i64 16
%11 = getelementptr inbounds i8, i8* %0, i64 2072
%12 = tail call i32 @edc_computeblock(i8* %10, i32 2056, i8* %11)
%13 = tail call i32 @ecc_generate(i8* %0, i32 1)
br label %18
14: ; preds = %2
%15 = getelementptr inbounds i8, i8* %0, i64 16
%16 = getelementptr inbounds i8, i8* %0, i64 2348
%17 = tail call i32 @edc_computeblock(i8* %15, i32 2332, i8* %16)
br label %18
18: ; preds = %2, %14, %9, %3
ret void
}