#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 */
unsigned char *calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
void L2_scrambler(void) {
  int i;
  unsigned short scr;
  unsigned char *l2_scrambler, *scrtabp;
  l2_scrambler = calloc(2340, 1);
  if (l2_scrambler == NULL) {
    fprintf(stderr,
            "sorry, no memory for scrambler table generation. Aborted.\n");
    exit(1);
  }
  scrtabp = l2_scrambler;
  scr = 0x1;
  printf("static unsigned char yellowbook_scrambler[2340] = {\n  ");
  for (i = 0; i < 2340; i++) {
    int j;
    for (j = 0; j < 8; j++) {
      if (scr & 1) {
        *scrtabp |= 1 << j;
      }
      if ((scr & 1) ^ ((scr >> 1) & 1)) {
        scr |= 1 << 15;
      }
      scr = scr >> 1;
    }
    printf("%d,", *scrtabp);
    if (((i + 1) % 23) == 0)
      printf("\n  ");
    scrtabp++;
  }
  printf("\n};\n");
}


x86 assembly (clang, -O0):
<L2_scrambler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x924,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1185 <L2_scrambler+0x45>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movw   $0x1,-0x6(%rbp)
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x924,-0x4(%rbp)
jge    1281 <L2_scrambler+0x141>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    122d <L2_scrambler+0xed>
movzwl -0x6(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11eb <L2_scrambler+0xab>
mov    -0x1c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    -0x18(%rbp),%rax
movzbl (%rax),%ecx
or     %edx,%ecx
mov    %cl,(%rax)
movzwl -0x6(%rbp),%eax
and    $0x1,%eax
movzwl -0x6(%rbp),%ecx
sar    $0x1,%ecx
and    $0x1,%ecx
xor    %ecx,%eax
cmp    $0x0,%eax
je     1214 <L2_scrambler+0xd4>
movzwl -0x6(%rbp),%eax
or     $0x8000,%eax
mov    %ax,-0x6(%rbp)
movzwl -0x6(%rbp),%eax
sar    $0x1,%eax
mov    %ax,-0x6(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11bc <L2_scrambler+0x7c>
mov    -0x18(%rbp),%rax
movzbl (%rax),%esi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    $0x17,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1267 <L2_scrambler+0x127>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11a8 <L2_scrambler+0x68>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<L2_scrambler>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x924,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     131f <L2_scrambler+0x1cf>
mov    %rax,%r14
lea    0xebe(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r12w
mov    $0x1,%r13d
lea    0xedc(%rip),%r15
xor    %ebp,%ebp
jmp    11b4 <L2_scrambler+0x64>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
add    $0x1,%r13
cmp    $0x924,%ebp
je     1305 <L2_scrambler+0x1b5>
mov    %r13,%rax
movabs $0x642c8590b21642c9,%rcx
85 2c 64
mul    %rcx
movzwl %r12w,%ecx
mov    %ecx,%esi
and    $0x1,%esi
je     11d4 <L2_scrambler+0x84>
orb    $0x1,(%r14,%rbp,1)
shr    %ecx
mov    %ecx,%edi
and    $0x1,%edi
mov    %ecx,%eax
or     $0x4000,%eax
cmp    %edi,%esi
cmove  %ecx,%eax
mov    %eax,%ecx
and    $0x1,%ecx
je     11f3 <L2_scrambler+0xa3>
orb    $0x2,(%r14,%rbp,1)
shr    %eax
mov    %eax,%edi
and    $0x1,%edi
lea    0x4000(%rax),%esi
cmp    %edi,%ecx
cmove  %eax,%esi
mov    %esi,%eax
and    $0x1,%eax
je     1211 <L2_scrambler+0xc1>
orb    $0x4,(%r14,%rbp,1)
shr    %esi
mov    %esi,%edi
and    $0x1,%edi
lea    0x4000(%rsi),%ecx
cmp    %edi,%eax
cmove  %esi,%ecx
mov    %ecx,%edi
and    $0x1,%edi
je     122f <L2_scrambler+0xdf>
orb    $0x8,(%r14,%rbp,1)
mov    %r13,%rax
sub    %rdx,%rax
shr    %ecx
mov    %ecx,%ebx
and    $0x1,%ebx
lea    0x4000(%rcx),%esi
cmp    %ebx,%edi
cmove  %ecx,%esi
mov    %esi,%edi
and    $0x1,%edi
je     1253 <L2_scrambler+0x103>
orb    $0x10,(%r14,%rbp,1)
shr    %rax
shr    %esi
mov    %esi,%ebx
and    $0x1,%ebx
lea    0x4000(%rsi),%ecx
cmp    %ebx,%edi
cmove  %esi,%ecx
mov    %ecx,%esi
and    $0x1,%esi
je     1274 <L2_scrambler+0x124>
orb    $0x20,(%r14,%rbp,1)
add    %rdx,%rax
shr    %ecx
mov    %ecx,%edi
and    $0x1,%edi
lea    0x4000(%rcx),%edx
cmp    %edi,%esi
cmove  %ecx,%edx
mov    %edx,%esi
and    $0x1,%esi
je     1295 <L2_scrambler+0x145>
orb    $0x40,(%r14,%rbp,1)
shr    $0x4,%rax
shr    %edx
mov    %edx,%edi
and    $0x1,%edi
lea    0x4000(%rdx),%ecx
cmp    %edi,%esi
cmove  %edx,%ecx
mov    %ecx,%esi
movzbl (%r14,%rbp,1),%edx
and    $0x1,%esi
je     12be <L2_scrambler+0x16e>
or     $0x80,%dl
mov    %dl,(%r14,%rbp,1)
lea    (%rax,%rax,2),%rdi
not    %rax
lea    (%rax,%rdi,8),%rbx
shr    %ecx
mov    %ecx,%eax
and    $0x1,%eax
lea    0x4000(%rcx),%r12d
cmp    %eax,%esi
cmove  %ecx,%r12d
movzbl %dl,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %ebp,%ebx
jne    11a0 <L2_scrambler+0x50>
lea    0xd75(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a0 <L2_scrambler+0x50>
lea    0xd6a(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
lea    0xcd1(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [59 x i8] c"sorry, no memory for scrambler table generation. Aborted.\0A\00"
@.str.1 = [55 x i8] c"static unsigned char yellowbook_scrambler[2340] = {\0A \00"
@.str.2 = [4 x i8] c"%d,\00"
@.str.3 = [4 x i8] c"\0A \00"
@.str.4 = [5 x i8] c"\0A};\0A\00"
define void @L2_scrambler() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = call i8* @calloc(i32 2340, i32 1)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = load i8*, i8** %3
store i8* %14, i8** %4
store i16 1, i16* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %16
16: ; preds = %73, %13
%17 = load i32, i32* %1
%18 = icmp slt i32 %17, 2340
br i1 %18, label %19, label %76
19: ; preds = %16
store i32 0, i32* %5
br label %20
20: ; preds = %56, %19
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 8
br i1 %22, label %23, label %59
23: ; preds = %20
%24 = load i16, i16* %2
%25 = zext i16 %24 to i32
%26 = and i32 %25, 1
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %23
%29 = load i32, i32* %5
%30 = shl i32 1, %29
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = or i32 %33, %30
%35 = trunc i32 %34 to i8
store i8 %35, i8* %31
br label %36
36: ; preds = %28, %23
%37 = load i16, i16* %2
%38 = zext i16 %37 to i32
%39 = and i32 %38, 1
%40 = load i16, i16* %2
%41 = zext i16 %40 to i32
%42 = ashr i32 %41, 1
%43 = and i32 %42, 1
%44 = xor i32 %39, %43
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %36
%47 = load i16, i16* %2
%48 = zext i16 %47 to i32
%49 = or i32 %48, 32768
%50 = trunc i32 %49 to i16
store i16 %50, i16* %2
br label %51
51: ; preds = %46, %36
%52 = load i16, i16* %2
%53 = zext i16 %52 to i32
%54 = ashr i32 %53, 1
%55 = trunc i32 %54 to i16
store i16 %55, i16* %2
br label %56
56: ; preds = %51
%57 = load i32, i32* %5
%58 = add nsw i32 %57, 1
store i32 %58, i32* %5
br label %20
59: ; preds = %20
%60 = load i8*, i8** %4
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %62)
%64 = load i32, i32* %1
%65 = add nsw i32 %64, 1
%66 = srem i32 %65, 23
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %59
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %70
70: ; preds = %68, %59
%71 = load i8*, i8** %4
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %4
br label %73
73: ; preds = %70
%74 = load i32, i32* %1
%75 = add nsw i32 %74, 1
store i32 %75, i32* %1
br label %16
76: ; preds = %16
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [59 x i8] c"sorry, no memory for scrambler table generation. Aborted.\0A\00"
@.str.1 = [55 x i8] c"static unsigned char yellowbook_scrambler[2340] = {\0A \00"
@.str.2 = [4 x i8] c"%d,\00"
@.str.3 = [4 x i8] c"\0A \00"
@str = [4 x i8] c"\0A};\00"
define void @L2_scrambler() {
%1 = tail call dereferenceable_or_null(2340) i8* @calloc(i32 2340, i32 1)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %125
%10 = phi i8* [ %1, %7 ], [ %126, %125 ]
%11 = phi i32 [ 0, %7 ], [ %120, %125 ]
%12 = phi i16 [ 1, %7 ], [ %117, %125 ]
%13 = zext i16 %12 to i32
%14 = and i32 %13, 1
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %9
%17 = load i8, i8* %10
%18 = or i8 %17, 1
store i8 %18, i8* %10
br label %19
19: ; preds = %16, %9
%20 = lshr i32 %13, 1
%21 = and i32 %20, 1
%22 = icmp eq i32 %14, %21
%23 = lshr i16 %12, 1
%24 = or i16 %23, 16384
%25 = select i1 %22, i16 %23, i16 %24
%26 = zext i16 %25 to i32
%27 = and i32 %26, 1
%28 = icmp eq i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %19
%30 = load i8, i8* %10
%31 = or i8 %30, 2
store i8 %31, i8* %10
br label %32
32: ; preds = %29, %19
%33 = lshr i32 %26, 1
%34 = and i32 %33, 1
%35 = icmp eq i32 %27, %34
%36 = lshr i16 %25, 1
%37 = or i16 %36, 16384
%38 = select i1 %35, i16 %36, i16 %37
%39 = zext i16 %38 to i32
%40 = and i32 %39, 1
%41 = icmp eq i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %32
%43 = load i8, i8* %10
%44 = or i8 %43, 4
store i8 %44, i8* %10
br label %45
45: ; preds = %42, %32
%46 = lshr i32 %39, 1
%47 = and i32 %46, 1
%48 = icmp eq i32 %40, %47
%49 = lshr i16 %38, 1
%50 = or i16 %49, 16384
%51 = select i1 %48, i16 %49, i16 %50
%52 = zext i16 %51 to i32
%53 = and i32 %52, 1
%54 = icmp eq i32 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %45
%56 = load i8, i8* %10
%57 = or i8 %56, 8
store i8 %57, i8* %10
br label %58
58: ; preds = %55, %45
%59 = lshr i32 %52, 1
%60 = and i32 %59, 1
%61 = icmp eq i32 %53, %60
%62 = lshr i16 %51, 1
%63 = or i16 %62, 16384
%64 = select i1 %61, i16 %62, i16 %63
%65 = zext i16 %64 to i32
%66 = and i32 %65, 1
%67 = icmp eq i32 %66, 0
br i1 %67, label %71, label %68
68: ; preds = %58
%69 = load i8, i8* %10
%70 = or i8 %69, 16
store i8 %70, i8* %10
br label %71
71: ; preds = %68, %58
%72 = lshr i32 %65, 1
%73 = and i32 %72, 1
%74 = icmp eq i32 %66, %73
%75 = lshr i16 %64, 1
%76 = or i16 %75, 16384
%77 = select i1 %74, i16 %75, i16 %76
%78 = zext i16 %77 to i32
%79 = and i32 %78, 1
%80 = icmp eq i32 %79, 0
br i1 %80, label %84, label %81
81: ; preds = %71
%82 = load i8, i8* %10
%83 = or i8 %82, 32
store i8 %83, i8* %10
br label %84
84: ; preds = %81, %71
%85 = lshr i32 %78, 1
%86 = and i32 %85, 1
%87 = icmp eq i32 %79, %86
%88 = lshr i16 %77, 1
%89 = or i16 %88, 16384
%90 = select i1 %87, i16 %88, i16 %89
%91 = zext i16 %90 to i32
%92 = and i32 %91, 1
%93 = icmp eq i32 %92, 0
br i1 %93, label %97, label %94
94: ; preds = %84
%95 = load i8, i8* %10
%96 = or i8 %95, 64
store i8 %96, i8* %10
br label %97
97: ; preds = %94, %84
%98 = lshr i32 %91, 1
%99 = and i32 %98, 1
%100 = icmp eq i32 %92, %99
%101 = lshr i16 %90, 1
%102 = or i16 %101, 16384
%103 = select i1 %100, i16 %101, i16 %102
%104 = zext i16 %103 to i32
%105 = and i32 %104, 1
%106 = icmp eq i32 %105, 0
%107 = load i8, i8* %10
br i1 %106, label %110, label %108
108: ; preds = %97
%109 = or i8 %107, -128
store i8 %109, i8* %10
br label %110
110: ; preds = %97, %108
%111 = phi i8 [ %109, %108 ], [ %107, %97 ]
%112 = lshr i32 %104, 1
%113 = and i32 %112, 1
%114 = icmp eq i32 %105, %113
%115 = lshr i16 %103, 1
%116 = or i16 %115, 16384
%117 = select i1 %114, i16 %115, i16 %116
%118 = zext i8 %111 to i32
%119 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %118)
%120 = add nuw nsw i32 %11, 1
%121 = urem i32 %120, 23
%122 = icmp eq i32 %121, 0
br i1 %122, label %123, label %125
123: ; preds = %110
%124 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %125
125: ; preds = %123, %110
%126 = getelementptr inbounds i8, i8* %10, i64 1
%127 = icmp eq i32 %120, 2340
br i1 %127, label %128, label %9
128: ; preds = %125
%129 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
ret void
}