#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*/ s2;
typedef int /*<<< orphan*/ s1;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ gicSwapBytes(char *, int);
int gicReadRecordHelper(FILE *f, long size, void *buffer, int *wrong_order) {
  int s1, s2;
  if (buffer == NULL)
    return -1;
  if (f == NULL)
    return -2;
  if (fread(&s1, sizeof(int), 1, f) != 1)
    return 1;
  if (s1 == size) {
    *wrong_order = 0;
  } else {
    *wrong_order = 1;
    gicSwapBytes((char *)&(s1), sizeof(s1));
  }
  if (s1 != size)
    return 1;
  if (fread(buffer, size, 1, f) != 1)
    return 1;
  if (fread(&s2, sizeof(int), 1, f) != 1)
    return 1;
  if (*wrong_order) {
    gicSwapBytes((char *)&(s2), sizeof(s2));
  }
  if (s2 != size)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<gicReadRecordHelper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    114f <gicReadRecordHelper+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1276 <gicReadRecordHelper+0x156>
cmpq   $0x0,-0x10(%rbp)
jne    1166 <gicReadRecordHelper+0x46>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1276 <gicReadRecordHelper+0x156>
mov    -0x10(%rbp),%rcx
lea    -0x2c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     1192 <gicReadRecordHelper+0x72>
movl   $0x1,-0x4(%rbp)
jmp    1276 <gicReadRecordHelper+0x156>
movslq -0x2c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11af <gicReadRecordHelper+0x8f>
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
jmp    11c7 <gicReadRecordHelper+0xa7>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
lea    -0x2c(%rbp),%rdi
mov    $0x4,%esi
call   1030 <gicSwapBytes@plt>
movslq -0x2c(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11e1 <gicReadRecordHelper+0xc1>
movl   $0x1,-0x4(%rbp)
jmp    1276 <gicReadRecordHelper+0x156>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     120e <gicReadRecordHelper+0xee>
movl   $0x1,-0x4(%rbp)
jmp    1276 <gicReadRecordHelper+0x156>
mov    -0x10(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     123a <gicReadRecordHelper+0x11a>
movl   $0x1,-0x4(%rbp)
jmp    1276 <gicReadRecordHelper+0x156>
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
je     1255 <gicReadRecordHelper+0x135>
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
call   1030 <gicSwapBytes@plt>
movslq -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     126f <gicReadRecordHelper+0x14f>
movl   $0x1,-0x4(%rbp)
jmp    1276 <gicReadRecordHelper+0x156>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gicReadRecordHelper>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %rdx,%rdx
je     117b <gicReadRecordHelper+0x5b>
mov    %rdi,%rbx
test   %rdi,%rdi
je     1186 <gicReadRecordHelper+0x66>
mov    %rcx,%r14
mov    %rdx,%rbp
mov    %rsi,%r15
lea    0x8(%rsp),%rdi
mov    $0x1,%r12d
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1216 <gicReadRecordHelper+0xf6>
movslq 0x8(%rsp),%rax
cmp    %r15,%rax
jne    1191 <gicReadRecordHelper+0x71>
movl   $0x0,(%r14)
jmp    11ab <gicReadRecordHelper+0x8b>
mov    $0xffffffff,%r12d
jmp    1216 <gicReadRecordHelper+0xf6>
mov    $0xfffffffe,%r12d
jmp    1216 <gicReadRecordHelper+0xf6>
movl   $0x1,(%r14)
lea    0x8(%rsp),%rdi
mov    $0x4,%esi
call   1030 <gicSwapBytes@plt>
mov    0x8(%rsp),%eax
cltq
cmp    %r15,%rax
jne    1216 <gicReadRecordHelper+0xf6>
mov    $0x1,%r12d
mov    %rbp,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1216 <gicReadRecordHelper+0xf6>
lea    0xc(%rsp),%rdi
mov    $0x1,%r12d
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1216 <gicReadRecordHelper+0xf6>
cmpl   $0x0,(%r14)
je     1207 <gicReadRecordHelper+0xe7>
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
call   1030 <gicSwapBytes@plt>
movslq 0xc(%rsp),%rax
xor    %r12d,%r12d
cmp    %r15,%rax
setne  %r12b
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gicReadRecordHelper(i32* %0, i64 %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%12 = load i8*, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %4
store i32 -1, i32* %5
br label %69
15: ; preds = %4
%16 = load i32*, i32** %6
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 -2, i32* %5
br label %69
19: ; preds = %15
%20 = load i32*, i32** %6
%21 = call i32 @fread(i32* %10, i32 4, i32 1, i32* %20)
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 1, i32* %5
br label %69
24: ; preds = %19
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = load i64, i64* %7
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = load i32*, i32** %9
store i32 0, i32* %30
br label %35
31: ; preds = %24
%32 = load i32*, i32** %9
store i32 1, i32* %32
%33 = bitcast i32* %10 to i8*
%34 = call i32 @gicSwapBytes(i8* %33, i32 4)
br label %35
35: ; preds = %31, %29
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = load i64, i64* %7
%39 = icmp ne i64 %37, %38
br i1 %39, label %40, label %41
40: ; preds = %35
store i32 1, i32* %5
br label %69
41: ; preds = %35
%42 = load i8*, i8** %8
%43 = bitcast i8* %42 to i32*
%44 = load i64, i64* %7
%45 = trunc i64 %44 to i32
%46 = load i32*, i32** %6
%47 = call i32 @fread(i32* %43, i32 %45, i32 1, i32* %46)
%48 = icmp ne i32 %47, 1
br i1 %48, label %49, label %50
49: ; preds = %41
store i32 1, i32* %5
br label %69
50: ; preds = %41
%51 = load i32*, i32** %6
%52 = call i32 @fread(i32* %11, i32 4, i32 1, i32* %51)
%53 = icmp ne i32 %52, 1
br i1 %53, label %54, label %55
54: ; preds = %50
store i32 1, i32* %5
br label %69
55: ; preds = %50
%56 = load i32*, i32** %9
%57 = load i32, i32* %56
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = bitcast i32* %11 to i8*
%61 = call i32 @gicSwapBytes(i8* %60, i32 4)
br label %62
62: ; preds = %59, %55
%63 = load i32, i32* %11
%64 = sext i32 %63 to i64
%65 = load i64, i64* %7
%66 = icmp ne i64 %64, %65
br i1 %66, label %67, label %68
67: ; preds = %62
store i32 1, i32* %5
br label %69
68: ; preds = %62
store i32 0, i32* %5
br label %69
69: ; preds = %68, %67, %54, %49, %40, %23, %18, %14
%70 = load i32, i32* %5
ret i32 %70
}

LLVM IR (-O2):
define i32 @gicReadRecordHelper(i32* %0, i64 %1, i8* %2, i32* nocapture %3) {
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = icmp eq i8* %2, null
br i1 %9, label %45, label %10
10: ; preds = %4
%11 = icmp eq i32* %0, null
br i1 %11, label %45, label %12
12: ; preds = %10
%13 = call i32 @fread(i32* %5, i32 4, i32 1, i32* %0)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %45
15: ; preds = %12
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = icmp eq i64 %17, %1
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 0, i32* %3
br label %23
20: ; preds = %15
store i32 1, i32* %3
%21 = call i32 @gicSwapBytes(i8* %7, i32 4)
%22 = load i32, i32* %5
br label %23
23: ; preds = %20, %19
%24 = phi i32 [ %22, %20 ], [ %16, %19 ]
%25 = sext i32 %24 to i64
%26 = icmp eq i64 %25, %1
br i1 %26, label %27, label %45
27: ; preds = %23
%28 = bitcast i8* %2 to i32*
%29 = trunc i64 %1 to i32
%30 = call i32 @fread(i32* %28, i32 %29, i32 1, i32* %0)
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %45
32: ; preds = %27
%33 = call i32 @fread(i32* %6, i32 4, i32 1, i32* %0)
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %45
35: ; preds = %32
%36 = load i32, i32* %3
%37 = icmp eq i32 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = call i32 @gicSwapBytes(i8* %8, i32 4)
br label %40
40: ; preds = %38, %35
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = icmp ne i64 %42, %1
%44 = zext i1 %43 to i32
br label %45
45: ; preds = %40, %32, %27, %23, %12, %10, %4
%46 = phi i32 [ -1, %4 ], [ -2, %10 ], [ 1, %12 ], [ 1, %23 ], [ 1, %27 ], [ 1, %32 ], [ %44, %40 ]
ret i32 %46
}