#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 uint8_t;
typedef int uint32_t;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int random();
int rs_decode(int *);
int /*<<< orphan*/ rs_encode(int *, int, int *);
int /*<<< orphan*/ rs_init();
int snprintf(char *, int, char *, int);
int /*<<< orphan*/ srandom(int);
scalar_t__ time(int /*<<< orphan*/ *);
int32_t main(void) {
  int32_t i, len, err;
  uint8_t buf[((1 << 8) - 1)];
  rs_init();
  srandom((uint32_t)time(NULL));
  while (!0) {
    for (i = 0; i < ((1 << 8) - 1); i++) {
      buf[i] = 0;
    }
    len = snprintf((char *)buf, ((1 << 8) - 1), "%u", (uint32_t)random());
    rs_encode(buf, len, &buf[(((1 << 8) - 1) - (16 * 2))]);
    buf[random() % len] = 'x';
    err = rs_decode(buf);
    printf("Data:");
    for (i = 0; i < ((1 << 8) - 1); i++) {
      if (i % 16 == 0) {
        printf("\n  %03x:", i);
      }
      printf(" %02x", buf[i]);
    }
    printf("\n");
    printf("Buffer had %d bytes with %d errors.\n", len, err);
    if (!err) {
      printf("Buffer decoded successfully.\n");
    } else if (err > 0) {
      printf("Buffer corrected %d errors.\n", err);
    } else {
      printf("Buffer was not decoded successfully.\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10a0 <rs_init@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0xff,-0x8(%rbp)
jge    11da <main+0x5a>
movslq -0x8(%rbp),%rax
movl   $0x0,-0x410(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b0 <main+0x30>
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
mov    $0x0,%al
call   1080 <random@plt>
mov    -0x418(%rbp),%rdi
mov    %eax,%ecx
mov    $0xff,%esi
lea    0xdfc(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x410(%rbp),%rdx
add    $0x37c,%rdx
call   1070 <rs_encode@plt>
mov    $0x0,%al
call   1080 <random@plt>
cltd
idivl  -0xc(%rbp)
movslq %edx,%rax
movl   $0x78,-0x410(%rbp,%rax,4)
lea    -0x410(%rbp),%rdi
call   1090 <rs_decode@plt>
mov    %eax,-0x10(%rbp)
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0xff,-0x8(%rbp)
jge    12bf <main+0x13f>
mov    -0x8(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1298 <main+0x118>
mov    -0x8(%rbp),%esi
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x8(%rbp),%rax
mov    -0x410(%rbp,%rax,4),%esi
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1266 <main+0xe6>
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xd3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
jne    12fe <main+0x17e>
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1331 <main+0x1b1>
cmpl   $0x0,-0x10(%rbp)
jle    131e <main+0x19e>
mov    -0x10(%rbp),%esi
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    132c <main+0x1ac>
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1331 <main+0x1b1>
jmp    11a9 <main+0x29>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
xor    %eax,%eax
call   10d0 <rs_init@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1040 <srandom@plt>
mov    %rsp,%r13
lea    0xe29(%rip),%rbx
lea    0xe2b(%rip),%rbp
jmp    11fc <main+0x4c>
nopl   0x0(%rax)
lea    0xe63(%rip),%rdi
call   1050 <puts@plt>
mov    $0x3fc,%edx
mov    %r13,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
xor    %eax,%eax
call   10b0 <random@plt>
mov    %r13,%rdi
mov    $0xff,%esi
lea    0xddf(%rip),%rdx
mov    %eax,%ecx
call   1070 <snprintf@plt>
mov    %eax,%r15d
mov    %r13,%rdi
mov    %eax,%esi
lea    0x37c(%rsp),%rdx
call   10a0 <rs_encode@plt>
xor    %eax,%eax
call   10b0 <random@plt>
cltd
idiv   %r15d
movslq %edx,%rax
movl   $0x78,(%rsp,%rax,4)
mov    %r13,%rdi
call   10c0 <rs_decode@plt>
mov    %eax,%r12d
lea    0xd9f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %r14d,%r14d
jmp    128b <main+0xdb>
mov    (%rsp,%r14,4),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r14
cmp    $0xff,%r14
je     12a0 <main+0xf0>
test   $0xf,%r14b
jne    1270 <main+0xc0>
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1270 <main+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xd67(%rip),%rdi
mov    %r15d,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
test   %r12d,%r12d
je     11f0 <main+0x40>
jle    12e0 <main+0x130>
lea    0xd6d(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11fc <main+0x4c>
nop
lea    0xd90(%rip),%rdi
call   1050 <puts@plt>
jmp    11fc <main+0x4c>

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
@.str.1 = [6 x i8] c"Data:\00"
@.str.2 = [9 x i8] c"\0A %03x:\00"
@.str.3 = [6 x i8] c" %02x\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [37 x i8] c"Buffer had %d bytes with %d errors.\0A\00"
@.str.6 = [30 x i8] c"Buffer decoded successfully.\0A\00"
@.str.7 = [29 x i8] c"Buffer corrected %d errors.\0A\00"
@.str.8 = [38 x i8] c"Buffer was not decoded successfully.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [255 x i32]
store i32 0, i32* %1
%6 = call i32 (...) @rs_init()
%7 = call i64 @time(i32* null)
%8 = trunc i64 %7 to i32
%9 = call i32 @srandom(i32 %8)
br label %10
10: ; preds = %0, %75
store i32 0, i32* %2
br label %11
11: ; preds = %18, %10
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 255
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [255 x i32], [255 x i32]* %5, i64 0, i64 %16
store i32 0, i32* %17
br label %18
18: ; preds = %14
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %11
21: ; preds = %11
%22 = getelementptr inbounds [255 x i32], [255 x i32]* %5, i64 0, i64 0
%23 = bitcast i32* %22 to i8*
%24 = call i32 (...) @random()
%25 = call i32 @snprintf(i8* %23, i32 255, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %24)
store i32 %25, i32* %3
%26 = getelementptr inbounds [255 x i32], [255 x i32]* %5, i64 0, i64 0
%27 = load i32, i32* %3
%28 = getelementptr inbounds [255 x i32], [255 x i32]* %5, i64 0, i64 223
%29 = call i32 @rs_encode(i32* %26, i32 %27, i32* %28)
%30 = call i32 (...) @random()
%31 = load i32, i32* %3
%32 = srem i32 %30, %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [255 x i32], [255 x i32]* %5, i64 0, i64 %33
store i32 120, i32* %34
%35 = getelementptr inbounds [255 x i32], [255 x i32]* %5, i64 0, i64 0
%36 = call i32 @rs_decode(i32* %35)
store i32 %36, i32* %4
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %38
38: ; preds = %54, %21
%39 = load i32, i32* %2
%40 = icmp slt i32 %39, 255
br i1 %40, label %41, label %57
41: ; preds = %38
%42 = load i32, i32* %2
%43 = srem i32 %42, 16
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* %2
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %45, %41
%49 = load i32, i32* %2
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [255 x i32], [255 x i32]* %5, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %48
%55 = load i32, i32* %2
%56 = add nsw i32 %55, 1
store i32 %56, i32* %2
br label %38
57: ; preds = %38
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%59 = load i32, i32* %3
%60 = load i32, i32* %4
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %59, i32 %60)
%62 = load i32, i32* %4
%63 = icmp ne i32 %62, 0
br i1 %63, label %66, label %64
64: ; preds = %57
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
br label %75
66: ; preds = %57
%67 = load i32, i32* %4
%68 = icmp sgt i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load i32, i32* %4
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i32 %70)
br label %74
72: ; preds = %66
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0))
br label %74
74: ; preds = %72, %69
br label %75
75: ; preds = %74, %64
br label %10
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
@.str.1 = [6 x i8] c"Data:\00"
@.str.2 = [9 x i8] c"\0A %03x:\00"
@.str.3 = [6 x i8] c" %02x\00"
@.str.5 = [37 x i8] c"Buffer had %d bytes with %d errors.\0A\00"
@.str.7 = [29 x i8] c"Buffer corrected %d errors.\0A\00"
@str = [29 x i8] c"Buffer decoded successfully.\00"
@str.9 = [37 x i8] c"Buffer was not decoded successfully.\00"
define i32 @main() {
%1 = alloca [255 x i32]
%2 = bitcast [255 x i32]* %1 to i8*
%3 = tail call i32 (...) @rs_init()
%4 = tail call i64 @time(i32* null)
%5 = trunc i64 %4 to i32
%6 = tail call i32 @srandom(i32 %5)
%7 = getelementptr inbounds [255 x i32], [255 x i32]* %1, i64 0, i64 0
%8 = getelementptr inbounds [255 x i32], [255 x i32]* %1, i64 0, i64 223
br label %9
9: ; preds = %42, %0
%10 = call i32 (...) @random()
%11 = call i32 @snprintf(i8* %2, i32 255, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 @rs_encode(i32* %7, i32 %11, i32* %8)
%13 = call i32 (...) @random()
%14 = srem i32 %13, %11
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [255 x i32], [255 x i32]* %1, i64 0, i64 %15
store i32 120, i32* %16
%17 = call i32 @rs_decode(i32* %7)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %9, %26
%20 = phi i64 [ 0, %9 ], [ %30, %26 ]
%21 = trunc i64 %20 to i32
%22 = and i32 %21, 15
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %26
26: ; preds = %24, %19
%27 = getelementptr inbounds [255 x i32], [255 x i32]* %1, i64 0, i64 %20
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = add nuw nsw i64 %20, 1
%31 = icmp eq i64 %30, 255
br i1 %31, label %32, label %19
32: ; preds = %26
%33 = call i32 @putchar(i32 10)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %11, i32 %17)
%35 = icmp eq i32 %17, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %42
38: ; preds = %32
%39 = icmp sgt i32 %17, 0
br i1 %39, label %40, label %43
40: ; preds = %38
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i32 %17)
br label %42
42: ; preds = %40, %43, %36
br label %9
43: ; preds = %38
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.9, i64 0, i64 0))
br label %42
}