#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*/ gcr_convert_4bytes_to_GCR(unsigned char *, unsigned char *);
int /*<<< orphan*/ memset(unsigned char *, int, int);
void gcr_convert_sector_to_GCR(unsigned char *buffer, unsigned char *ptr,
                               unsigned int track, unsigned int sector,
                               unsigned char diskID1, unsigned char diskID2,
                               unsigned char error_code) {
  int i;
  unsigned char buf[4], header_id1;
  header_id1 = (error_code == 29) ? diskID1 ^ 0xff : diskID1;
  memset(ptr, 0xff, 5);
  ptr += 5;
  buf[0] = (error_code == 20) ? 0xff : 0x08;
  buf[1] = sector ^ track ^ diskID2 ^ header_id1;
  buf[2] = sector;
  buf[3] = track;
  if (error_code == 27)
    buf[1] ^= 0xff;
  gcr_convert_4bytes_to_GCR(buf, ptr);
  ptr += 5;
  buf[0] = diskID2;
  buf[1] = header_id1;
  buf[2] = buf[3] = 0x0f;
  gcr_convert_4bytes_to_GCR(buf, ptr);
  ptr += 5;
  ptr += 9;
  memset(ptr, 0xff, 5);
  ptr += 5;
  for (i = 0; i < 65; i++) {
    gcr_convert_4bytes_to_GCR(buffer, ptr);
    buffer += 4;
    ptr += 5;
  }
}


x86 assembly (clang, -O0):
<gcr_convert_sector_to_GCR>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r8d,-0x3c(%rbp)
mov    %ecx,%eax
mov    -0x3c(%rbp),%ecx
mov    %eax,-0x38(%rbp)
mov    %edx,%eax
mov    -0x38(%rbp),%edx
mov    %eax,-0x34(%rbp)
mov    %rsi,%rax
mov    -0x34(%rbp),%esi
mov    %rax,-0x30(%rbp)
mov    %rdi,%r8
mov    -0x30(%rbp),%rdi
mov    %r9b,%al
mov    0x10(%rbp),%r9b
mov    %r8,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %cl,-0x19(%rbp)
mov    %al,-0x1a(%rbp)
movzbl 0x10(%rbp),%eax
cmp    $0x1d,%eax
jne    1186 <gcr_convert_sector_to_GCR+0x66>
movzbl -0x19(%rbp),%eax
xor    $0xff,%eax
mov    %eax,-0x40(%rbp)
jmp    118d <gcr_convert_sector_to_GCR+0x6d>
movzbl -0x19(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %al,-0x25(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xff,%esi
mov    $0x5,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
movzbl 0x10(%rbp),%edx
mov    $0x8,%eax
mov    $0xff,%ecx
cmp    $0x14,%edx
cmove  %ecx,%eax
mov    %al,-0x24(%rbp)
mov    -0x18(%rbp),%eax
xor    -0x14(%rbp),%eax
movzbl -0x1a(%rbp),%ecx
xor    %ecx,%eax
movzbl -0x25(%rbp),%ecx
xor    %ecx,%eax
mov    %al,-0x23(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,-0x22(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x21(%rbp)
movzbl 0x10(%rbp),%eax
cmp    $0x1b,%eax
jne    1203 <gcr_convert_sector_to_GCR+0xe3>
movzbl -0x23(%rbp),%eax
xor    $0xff,%eax
mov    %al,-0x23(%rbp)
lea    -0x24(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <gcr_convert_4bytes_to_GCR@plt>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1a(%rbp),%al
mov    %al,-0x24(%rbp)
mov    -0x25(%rbp),%al
mov    %al,-0x23(%rbp)
movb   $0xf,-0x21(%rbp)
movb   $0xf,-0x22(%rbp)
lea    -0x24(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <gcr_convert_4bytes_to_GCR@plt>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x9,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xff,%esi
mov    $0x5,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x41,-0x20(%rbp)
jge    12b8 <gcr_convert_sector_to_GCR+0x198>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <gcr_convert_4bytes_to_GCR@plt>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    127b <gcr_convert_sector_to_GCR+0x15b>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gcr_convert_sector_to_GCR>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r15d
mov    %ecx,%ebp
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%rbx
cmpb   $0x1d,0x40(%rsp)
sete   %r13b
neg    %r13b
xor    %r8b,%r13b
mov    %rsi,%rdi
mov    $0xff,%esi
mov    $0x5,%edx
call   1040 <memset@plt>
lea    0x5(%r14),%rsi
mov    0x40(%rsp),%cl
cmp    $0x14,%cl
mov    $0x8,%eax
mov    $0xff,%edx
cmove  %edx,%eax
mov    %al,0x4(%rsp)
mov    %ebp,%eax
xor    %r12d,%eax
xor    %r15d,%eax
xor    %r13b,%al
mov    %al,0x5(%rsp)
mov    %bpl,0x6(%rsp)
mov    %r12b,0x7(%rsp)
cmp    $0x1b,%cl
jne    119a <gcr_convert_sector_to_GCR+0x7a>
not    %al
mov    %al,0x5(%rsp)
lea    0x4(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <gcr_convert_4bytes_to_GCR@plt>
lea    0xa(%r14),%rsi
mov    %r15b,0x4(%rsp)
mov    %r13b,0x5(%rsp)
movw   $0xf0f,0x6(%rsp)
mov    %rbp,%rdi
call   1030 <gcr_convert_4bytes_to_GCR@plt>
lea    0x18(%r14),%rdi
mov    $0xff,%esi
mov    $0x5,%edx
call   1040 <memset@plt>
mov    $0x1d,%ebp
nopl   0x0(%rax)
lea    (%r14,%rbp,1),%rsi
mov    %rbx,%rdi
call   1030 <gcr_convert_4bytes_to_GCR@plt>
add    $0x4,%rbx
add    $0x5,%rbp
cmp    $0x162,%ebp
jne    11e0 <gcr_convert_sector_to_GCR+0xc0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @gcr_convert_sector_to_GCR(i8* %0, i8* %1, i32 %2, i32 %3, i8 zeroext %4, i8 zeroext %5, i8 zeroext %6) {
%8 = alloca [4 x i8]
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%10 = icmp eq i8 %6, 29
%11 = sext i1 %10 to i8
%12 = xor i8 %11, %4
%13 = tail call i32 @memset(i8* %1, i32 255, i32 5)
%14 = getelementptr inbounds i8, i8* %1, i64 5
%15 = icmp eq i8 %6, 20
%16 = select i1 %15, i8 -1, i8 8
store i8 %16, i8* %9
%17 = xor i32 %3, %2
%18 = trunc i32 %17 to i8
%19 = xor i8 %18, %5
%20 = xor i8 %19, %12
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 1
store i8 %20, i8* %21
%22 = trunc i32 %3 to i8
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 2
store i8 %22, i8* %23
%24 = trunc i32 %2 to i8
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 3
store i8 %24, i8* %25
%26 = icmp eq i8 %6, 27
br i1 %26, label %27, label %29
27: ; preds = %7
%28 = xor i8 %20, -1
store i8 %28, i8* %21
br label %29
29: ; preds = %27, %7
%30 = call i32 @gcr_convert_4bytes_to_GCR(i8* %9, i8* %14)
%31 = getelementptr inbounds i8, i8* %1, i64 10
store i8 %5, i8* %9
store i8 %12, i8* %21
store i8 15, i8* %25
store i8 15, i8* %23
%32 = call i32 @gcr_convert_4bytes_to_GCR(i8* %9, i8* %31)
%33 = getelementptr inbounds i8, i8* %1, i64 24
%34 = call i32 @memset(i8* %33, i32 255, i32 5)
%35 = getelementptr inbounds i8, i8* %1, i64 29
br label %36
36: ; preds = %29, %36
%37 = phi i8* [ %0, %29 ], [ %41, %36 ]
%38 = phi i32 [ 0, %29 ], [ %43, %36 ]
%39 = phi i8* [ %35, %29 ], [ %42, %36 ]
%40 = call i32 @gcr_convert_4bytes_to_GCR(i8* %37, i8* %39)
%41 = getelementptr inbounds i8, i8* %37, i64 4
%42 = getelementptr inbounds i8, i8* %39, i64 5
%43 = add nuw nsw i32 %38, 1
%44 = icmp eq i32 %43, 65
br i1 %44, label %45, label %36
45: ; preds = %36
ret void
}