#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
void compare(int cmpad, int size) {
  int i, indikator;
  char *dump = malloc(1024 + 4 * size);
  char *endian = malloc(1024);
  FILE *pFiledump;
  FILE *pFileendian;
  pFiledump = fopen("result_byte.txt", "r");
  pFileendian = fopen("referenzsystem.txt", "r");
  i = 0;
  while (i < cmpad) {
    i++;
    fscanf(pFiledump, "%s", dump);
    if ((dump[0] == '/') && (dump[1] == '/')) {
      while (fgetc(pFiledump) != '\n')
        ;
      i--;
    } else {
      printf("%d, %s \n", i, dump);
    }
  }
  indikator = 1;
  printf("index, s2pp-fpga, referenzsystem\n");
  for (i = 0; i < (4 * size); i++) {
    fscanf(pFiledump, "%s", dump);
    fscanf(pFileendian, "%s", endian);
    if (strcmp(dump, endian) != 0) {
      printf("%d mismatch in ", i);
      indikator = 0;
    }
    printf("%d, %s, %s \n", i, dump, endian);
  }
  fclose(pFiledump);
  fclose(pFileendian);
  free(endian);
  free(dump);
  if (indikator == 1)
    printf("match \n");
}


x86 assembly (clang, -O0):
<compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
shl    $0x2,%edi
add    $0x400,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x400,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe48(%rip),%rdi
lea    0xe51(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    0xe43(%rip),%rdi
lea    0xe3a(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1277 <compare+0xf7>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe1b(%rip),%rsi
call   1060 <fscanf@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    125d <compare+0xdd>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
jne    125d <compare+0xdd>
jmp    1235 <compare+0xb5>
mov    -0x28(%rbp),%rdi
call   1070 <fgetc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     124f <compare+0xcf>
jmp    1235 <compare+0xb5>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1272 <compare+0xf2>
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11e6 <compare+0x66>
movl   $0x1,-0x10(%rbp)
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    $0x2,%ecx
cmp    %ecx,%eax
jge    1322 <compare+0x1a2>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd72(%rip),%rsi
call   1060 <fscanf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd5e(%rip),%rsi
call   1060 <fscanf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     12fb <compare+0x17b>
mov    -0xc(%rbp),%esi
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1293 <compare+0x113>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x1,-0x10(%rbp)
jne    135e <compare+0x1de>
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
mov    %rsi,0x8(%rsp)
lea    0x400(,%rsi,4),%edi
call   10a0 <malloc@plt>
mov    %rax,%r12
mov    $0x400,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
lea    0xe38(%rip),%rdi
lea    0xe41(%rip),%r15
mov    %r15,%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
lea    0xe31(%rip),%rdi
mov    %r15,%rsi
call   10b0 <fopen@plt>
mov    %rax,0x10(%rsp)
test   %ebp,%ebp
jle    124e <compare+0xbe>
lea    0xe2c(%rip),%r13
xor    %r15d,%r15d
jmp    121d <compare+0x8d>
xchg   %ax,%ax
add    $0x1,%r15d
lea    0xe1d(%rip),%rdi
mov    %r15d,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
cmp    %ebp,%r15d
jge    124e <compare+0xbe>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1070 <fscanf@plt>
cmpb   $0x2f,(%r12)
jne    1200 <compare+0x70>
cmpb   $0x2f,0x1(%r12)
jne    1200 <compare+0x70>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <fgetc@plt>
cmp    $0xa,%al
jne    1240 <compare+0xb0>
jmp    1218 <compare+0x88>
lea    0xdf9(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%r15
test   %r15d,%r15d
jle    12f9 <compare+0x169>
shl    $0x2,%r15d
cmp    $0x2,%r15d
mov    $0x1,%eax
movl   $0x1,0x8(%rsp)
cmovl  %eax,%r15d
lea    0xd9d(%rip),%rbp
xor    %r13d,%r13d
jmp    12b0 <compare+0x120>
nopl   (%rax)
lea    0xdaa(%rip),%rdi
mov    %r13d,%esi
mov    %r12,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r13d
cmp    %r13d,%r15d
je     1301 <compare+0x171>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1070 <fscanf@plt>
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1070 <fscanf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1290 <compare+0x100>
movl   $0x0,0x8(%rsp)
lea    0xd44(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1290 <compare+0x100>
movl   $0x1,0x8(%rsp)
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x10(%rsp),%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
cmpl   $0x1,0x8(%rsp)
jne    1344 <compare+0x1b4>
lea    0xd3e(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"result_byte.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"referenzsystem.txt\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [9 x i8] c"%d, %s \0A\00"
@.str.5 = [34 x i8] c"index, s2pp-fpga, referenzsystem\0A\00"
@.str.6 = [16 x i8] c"%d mismatch in \00"
@.str.7 = [13 x i8] c"%d, %s, %s \0A\00"
@.str.8 = [8 x i8] c"match \0A\00"
define void @compare(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
store i32 %0, i32* %3
store i32 %1, i32* %4
%11 = load i32, i32* %4
%12 = mul nsw i32 4, %11
%13 = add nsw i32 1024, %12
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %7
%15 = call i8* @malloc(i32 1024)
store i8* %15, i8** %8
%16 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %9
%17 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %10
store i32 0, i32* %5
br label %18
18: ; preds = %53, %2
%19 = load i32, i32* %5
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %54
22: ; preds = %18
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
%25 = load i32*, i32** %9
%26 = load i8*, i8** %7
%27 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 47
br i1 %32, label %33, label %49
33: ; preds = %22
%34 = load i8*, i8** %7
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 47
br i1 %38, label %39, label %49
39: ; preds = %33
br label %40
40: ; preds = %45, %39
%41 = load i32*, i32** %9
%42 = call signext i8 @fgetc(i32* %41)
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 10
br i1 %44, label %45, label %46
45: ; preds = %40
br label %40
46: ; preds = %40
%47 = load i32, i32* %5
%48 = add nsw i32 %47, -1
store i32 %48, i32* %5
br label %53
49: ; preds = %33, %22
%50 = load i32, i32* %5
%51 = load i8*, i8** %7
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %50, i8* %51)
br label %53
53: ; preds = %49, %46
br label %18
54: ; preds = %18
store i32 1, i32* %6
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %5
br label %56
56: ; preds = %80, %54
%57 = load i32, i32* %5
%58 = load i32, i32* %4
%59 = mul nsw i32 4, %58
%60 = icmp slt i32 %57, %59
br i1 %60, label %61, label %83
61: ; preds = %56
%62 = load i32*, i32** %9
%63 = load i8*, i8** %7
%64 = call i32 @fscanf(i32* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %63)
%65 = load i32*, i32** %10
%66 = load i8*, i8** %8
%67 = call i32 @fscanf(i32* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %66)
%68 = load i8*, i8** %7
%69 = load i8*, i8** %8
%70 = call i64 @strcmp(i8* %68, i8* %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %61
%73 = load i32, i32* %5
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %73)
store i32 0, i32* %6
br label %75
75: ; preds = %72, %61
%76 = load i32, i32* %5
%77 = load i8*, i8** %7
%78 = load i8*, i8** %8
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %76, i8* %77, i8* %78)
br label %80
80: ; preds = %75
%81 = load i32, i32* %5
%82 = add nsw i32 %81, 1
store i32 %82, i32* %5
br label %56
83: ; preds = %56
%84 = load i32*, i32** %9
%85 = call i32 @fclose(i32* %84)
%86 = load i32*, i32** %10
%87 = call i32 @fclose(i32* %86)
%88 = load i8*, i8** %8
%89 = call i32 @free(i8* %88)
%90 = load i8*, i8** %7
%91 = call i32 @free(i8* %90)
%92 = load i32, i32* %6
%93 = icmp eq i32 %92, 1
br i1 %93, label %94, label %96
94: ; preds = %83
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
br label %96
96: ; preds = %94, %83
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"result_byte.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"referenzsystem.txt\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [9 x i8] c"%d, %s \0A\00"
@.str.6 = [16 x i8] c"%d mismatch in \00"
@.str.7 = [13 x i8] c"%d, %s, %s \0A\00"
@str = [33 x i8] c"index, s2pp-fpga, referenzsystem\00"
@str.9 = [7 x i8] c"match \00"
define void @compare(i32 %0, i32 %1) {
%3 = shl nsw i32 %1, 2
%4 = add nsw i32 %3, 1024
%5 = tail call i8* @malloc(i32 %4)
%6 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp sgt i32 %0, 0
br i1 %9, label %10, label %29
10: ; preds = %2
%11 = getelementptr inbounds i8, i8* %5, i64 1
br label %12
12: ; preds = %10, %26
%13 = phi i32 [ 0, %10 ], [ %27, %26 ]
%14 = add nsw i32 %13, 1
%15 = tail call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%16 = load i8, i8* %5
%17 = icmp eq i8 %16, 47
br i1 %17, label %18, label %24
18: ; preds = %12
%19 = load i8, i8* %11
%20 = icmp eq i8 %19, 47
br i1 %20, label %21, label %24
21: ; preds = %18, %21
%22 = tail call signext i8 @fgetc(i32* %7)
%23 = icmp eq i8 %22, 10
br i1 %23, label %26, label %21
24: ; preds = %18, %12
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %14, i8* %5)
br label %26
26: ; preds = %21, %24
%27 = phi i32 [ %14, %24 ], [ %13, %21 ]
%28 = icmp slt i32 %27, %0
br i1 %28, label %12, label %29
29: ; preds = %26, %2
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%31 = icmp sgt i32 %1, 0
br i1 %31, label %32, label %48
32: ; preds = %29
%33 = call i32 @llvm.smax.i32(i32 %3, i32 1)
br label %34
34: ; preds = %32, %43
%35 = phi i32 [ %46, %43 ], [ 0, %32 ]
%36 = phi i32 [ %44, %43 ], [ 1, %32 ]
%37 = tail call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%38 = tail call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%39 = tail call i64 @strcmp(i8* %5, i8* %6)
%40 = icmp eq i64 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %34
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %35)
br label %43
43: ; preds = %41, %34
%44 = phi i32 [ 0, %41 ], [ %36, %34 ]
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %35, i8* %5, i8* %6)
%46 = add nuw nsw i32 %35, 1
%47 = icmp eq i32 %46, %33
br i1 %47, label %48, label %34
48: ; preds = %43, %29
%49 = phi i32 [ 1, %29 ], [ %44, %43 ]
%50 = tail call i32 @fclose(i32* %7)
%51 = tail call i32 @fclose(i32* %8)
%52 = tail call i32 @free(i8* %6)
%53 = tail call i32 @free(i8* %5)
%54 = icmp eq i32 %49, 1
br i1 %54, label %55, label %57
55: ; preds = %48
%56 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.9, i64 0, i64 0))
br label %57
57: ; preds = %55, %48
ret void
}