#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 ecc_computeblock(unsigned char *, int, int, int, int, unsigned char *);
int ecc_generate(unsigned char *sector, int zeroaddress, unsigned char *dest) {
  int r;
  unsigned char address[4], i;
  if (zeroaddress)
    for (i = 0; i < 4; i++) {
      address[i] = sector[12 + i];
      sector[12 + i] = 0;
    }
  if (!(ecc_computeblock(sector + 0xC, 86, 24, 2, 86, dest + 0x81C - 0x81C))) {
    if (zeroaddress)
      for (i = 0; i < 4; i++)
        sector[12 + i] = address[i];
    return 0;
  }
  r = ecc_computeblock(sector + 0xC, 52, 43, 86, 88, dest + 0x8C8 - 0x81C);
  if (zeroaddress)
    for (i = 0; i < 4; i++)
      sector[12 + i] = address[i];
  return r;
}


x86 assembly (clang, -O0):
<ecc_generate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     117b <ecc_generate+0x6b>
movb   $0x0,-0x29(%rbp)
movzbl -0x29(%rbp),%eax
cmp    $0x4,%eax
jge    1176 <ecc_generate+0x66>
mov    -0x10(%rbp),%rax
movzbl -0x29(%rbp),%ecx
add    $0xc,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
movzbl -0x29(%rbp),%eax
mov    %cl,-0x28(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
movzbl -0x29(%rbp),%ecx
add    $0xc,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x29(%rbp),%al
add    $0x1,%al
mov    %al,-0x29(%rbp)
jmp    1131 <ecc_generate+0x21>
jmp    117b <ecc_generate+0x6b>
mov    -0x10(%rbp),%rdi
add    $0xc,%rdi
mov    -0x20(%rbp),%r9
add    $0x81c,%r9
add    $0xfffffffffffff7e4,%r9
mov    $0x56,%r8d
mov    $0x18,%edx
mov    $0x2,%ecx
mov    %r8d,%esi
call   1030 <ecc_computeblock@plt>
cmp    $0x0,%eax
jne    1208 <ecc_generate+0xf8>
cmpl   $0x0,-0x14(%rbp)
je     11fc <ecc_generate+0xec>
movb   $0x0,-0x29(%rbp)
movzbl -0x29(%rbp),%eax
cmp    $0x4,%eax
jge    11f7 <ecc_generate+0xe7>
movzbl -0x29(%rbp),%eax
mov    -0x28(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
movzbl -0x29(%rbp),%ecx
add    $0xc,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x29(%rbp),%al
add    $0x1,%al
mov    %al,-0x29(%rbp)
jmp    11c4 <ecc_generate+0xb4>
jmp    11fc <ecc_generate+0xec>
movl   $0x0,-0x4(%rbp)
jmp    128b <ecc_generate+0x17b>
mov    -0x10(%rbp),%rdi
add    $0xc,%rdi
mov    -0x20(%rbp),%r9
add    $0x8c8,%r9
add    $0xfffffffffffff7e4,%r9
mov    $0x34,%esi
mov    $0x2b,%edx
mov    $0x56,%ecx
mov    $0x58,%r8d
call   1030 <ecc_computeblock@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1285 <ecc_generate+0x175>
movb   $0x0,-0x29(%rbp)
movzbl -0x29(%rbp),%eax
cmp    $0x4,%eax
jge    1280 <ecc_generate+0x170>
movzbl -0x29(%rbp),%eax
mov    -0x28(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
movzbl -0x29(%rbp),%ecx
add    $0xc,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x29(%rbp),%al
add    $0x1,%al
mov    %al,-0x29(%rbp)
jmp    124d <ecc_generate+0x13d>
jmp    1285 <ecc_generate+0x175>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecc_generate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
lea    0xc(%rdi),%r14
test   %esi,%esi
je     11b0 <ecc_generate+0xa0>
mov    %rdi,%rbx
mov    0xc(%rdi),%bpl
mov    0xd(%rdi),%r12b
movw   $0x0,0xc(%rdi)
mov    0xe(%rdi),%r13b
mov    0xf(%rdi),%al
mov    %al,0x7(%rsp)
movw   $0x0,0xe(%rdi)
mov    %r14,%rdi
mov    $0x56,%esi
mov    $0x18,%edx
mov    $0x2,%ecx
mov    $0x56,%r8d
mov    %r15,%r9
call   1030 <ecc_computeblock@plt>
test   %eax,%eax
je     1209 <ecc_generate+0xf9>
add    $0xac,%r15
mov    %r14,%rdi
mov    $0x34,%esi
mov    $0x2b,%edx
mov    $0x56,%ecx
mov    $0x58,%r8d
mov    %r15,%r9
call   1030 <ecc_computeblock@plt>
mov    %bpl,0xc(%rbx)
mov    %r12b,0xd(%rbx)
mov    %r13b,0xe(%rbx)
mov    0x7(%rsp),%cl
mov    %cl,0xf(%rbx)
jmp    121e <ecc_generate+0x10e>
mov    %r14,%rdi
mov    $0x56,%esi
mov    $0x18,%edx
mov    $0x2,%ecx
mov    $0x56,%r8d
mov    %r15,%r9
call   1030 <ecc_computeblock@plt>
test   %eax,%eax
je     121c <ecc_generate+0x10c>
add    $0xac,%r15
mov    %r14,%rdi
mov    $0x34,%esi
mov    $0x2b,%edx
mov    $0x56,%ecx
mov    $0x58,%r8d
mov    %r15,%r9
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <ecc_computeblock@plt>
mov    %bpl,0xc(%rbx)
mov    %r12b,0xd(%rbx)
mov    %r13b,0xe(%rbx)
mov    0x7(%rsp),%al
mov    %al,0xf(%rbx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @ecc_generate(i8* %0, i32 %1, i8* %2) {
%4 = icmp eq i32 %1, 0
%5 = getelementptr inbounds i8, i8* %0, i64 12
br i1 %4, label %16, label %6
6: ; preds = %3
%7 = load i8, i8* %5
store i8 0, i8* %5
%8 = getelementptr inbounds i8, i8* %0, i64 13
%9 = load i8, i8* %8
store i8 0, i8* %8
%10 = getelementptr inbounds i8, i8* %0, i64 14
%11 = load i8, i8* %10
store i8 0, i8* %10
%12 = getelementptr inbounds i8, i8* %0, i64 15
%13 = load i8, i8* %12
store i8 0, i8* %12
%14 = tail call i32 @ecc_computeblock(i8* %5, i32 86, i32 24, i32 2, i32 86, i8* %2)
%15 = icmp eq i32 %14, 0
br i1 %15, label %22, label %23
16: ; preds = %3
%17 = tail call i32 @ecc_computeblock(i8* %5, i32 86, i32 24, i32 2, i32 86, i8* %2)
%18 = icmp eq i32 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %16
%20 = getelementptr inbounds i8, i8* %2, i64 172
%21 = tail call i32 @ecc_computeblock(i8* %5, i32 52, i32 43, i32 86, i32 88, i8* %20)
br label %26
22: ; preds = %6
store i8 %7, i8* %5
store i8 %9, i8* %8
store i8 %11, i8* %10
store i8 %13, i8* %12
br label %26
23: ; preds = %6
%24 = getelementptr inbounds i8, i8* %2, i64 172
%25 = tail call i32 @ecc_computeblock(i8* %5, i32 52, i32 43, i32 86, i32 88, i8* %24)
store i8 %7, i8* %5
store i8 %9, i8* %8
store i8 %11, i8* %10
store i8 %13, i8* %12
br label %26
26: ; preds = %23, %22, %16, %19
%27 = phi i32 [ %21, %19 ], [ 0, %16 ], [ 0, %22 ], [ %25, %23 ]
ret i32 %27
}