#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 int32_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int read(int, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ swap4(char *, int);
int read_c6(int fd, char *cstore, int size, int swap) {
  int n;
  int32_t rl1, rl2;
  n = read(fd, &rl1, 4);
  if (n == 0)
    return -1;
  if (swap)
    swap4((char *)&rl1, 1);
  n = read(fd, cstore, rl1);
  n = read(fd, &rl2, 4);
  if (swap)
    swap4((char *)&rl2, 1);
  if (rl1 != rl2) {
    fprintf(stderr, "Error read character block\n");
    return -2;
  }
  if (6 * size != rl2)
    fprintf(stderr, "read_c6: Expected %d, got %d elements\n", 6 * size, rl2);
  return 0;
}


x86 assembly (clang, -O0):
<read_c6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1171 <read_c6+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    122c <read_c6+0xfc>
cmpl   $0x0,-0x18(%rbp)
je     1189 <read_c6+0x59>
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1050 <swap4@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    $0x0,%al
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11cb <read_c6+0x9b>
lea    -0x24(%rbp),%rdi
mov    $0x1,%esi
call   1050 <swap4@plt>
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     11fa <read_c6+0xca>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    122c <read_c6+0xfc>
imul   $0x6,-0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     1225 <read_c6+0xf5>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
imul   $0x6,-0x14(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_c6>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%ebp
mov    %rsp,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <read@plt>
test   %eax,%eax
je     1199 <read_c6+0x69>
test   %ebx,%ebx
je     11a0 <read_c6+0x70>
mov    %rsp,%rdi
mov    $0x1,%esi
call   1050 <swap4@plt>
mov    (%rsp),%edx
mov    %ebp,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <read@plt>
lea    0x4(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <read@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <swap4@plt>
jmp    11c2 <read_c6+0x92>
mov    $0xffffffff,%ebx
jmp    120f <read_c6+0xdf>
mov    (%rsp),%edx
mov    %ebp,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <read@plt>
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <read@plt>
mov    (%rsp),%ecx
cmp    0x4(%rsp),%ecx
jne    11f3 <read_c6+0xc3>
add    %r14d,%r14d
lea    (%r14,%r14,2),%edx
xor    %ebx,%ebx
cmp    %ecx,%edx
je     120f <read_c6+0xdf>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    120f <read_c6+0xdf>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xfffffffe,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Error read character block\0A\00"
@.str.1 = [39 x i8] c"read_c6: Expected %d, got %d elements\0A\00"
define i32 @read_c6(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = load i32, i32* %6
%14 = call i32 (i32, ...) @read(i32 %13, i32* %11, i32 4)
store i32 %14, i32* %10
%15 = load i32, i32* %10
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 -1, i32* %5
br label %55
18: ; preds = %4
%19 = load i32, i32* %9
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = bitcast i32* %11 to i8*
%23 = call i32 @swap4(i8* %22, i32 1)
br label %24
24: ; preds = %21, %18
%25 = load i32, i32* %6
%26 = load i8*, i8** %7
%27 = load i32, i32* %11
%28 = call i32 (i32, ...) @read(i32 %25, i8* %26, i32 %27)
store i32 %28, i32* %10
%29 = load i32, i32* %6
%30 = call i32 (i32, ...) @read(i32 %29, i32* %12, i32 4)
store i32 %30, i32* %10
%31 = load i32, i32* %9
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %24
%34 = bitcast i32* %12 to i8*
%35 = call i32 @swap4(i8* %34, i32 1)
br label %36
36: ; preds = %33, %24
%37 = load i32, i32* %11
%38 = load i32, i32* %12
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 -2, i32* %5
br label %55
43: ; preds = %36
%44 = load i32, i32* %8
%45 = mul nsw i32 6, %44
%46 = load i32, i32* %12
%47 = icmp ne i32 %45, %46
br i1 %47, label %48, label %54
48: ; preds = %43
%49 = load i32, i32* @stderr
%50 = load i32, i32* %8
%51 = mul nsw i32 6, %50
%52 = load i32, i32* %12
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %51, i32 %52)
br label %54
54: ; preds = %48, %43
store i32 0, i32* %5
br label %55
55: ; preds = %54, %40, %17
%56 = load i32, i32* %5
ret i32 %56
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Error read character block\0A\00"
@.str.1 = [39 x i8] c"read_c6: Expected %d, got %d elements\0A\00"
define i32 @read_c6(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = call i32 (i32, ...) @read(i32 %0, i32* %5, i32 4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %36, label %11
11: ; preds = %4
%12 = icmp eq i32 %3, 0
br i1 %12, label %19, label %13
13: ; preds = %11
%14 = call i32 @swap4(i8* %7, i32 1)
%15 = load i32, i32* %5
%16 = call i32 (i32, ...) @read(i32 %0, i8* %1, i32 %15)
%17 = call i32 (i32, ...) @read(i32 %0, i32* %6, i32 4)
%18 = call i32 @swap4(i8* %8, i32 1)
br label %23
19: ; preds = %11
%20 = load i32, i32* %5
%21 = call i32 (i32, ...) @read(i32 %0, i8* %1, i32 %20)
%22 = call i32 (i32, ...) @read(i32 %0, i32* %6, i32 4)
br label %23
23: ; preds = %19, %13
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = icmp eq i32 %24, %25
br i1 %26, label %30, label %27
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %36
30: ; preds = %23
%31 = mul nsw i32 %2, 6
%32 = icmp eq i32 %31, %24
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %24)
br label %36
36: ; preds = %30, %33, %4, %27
%37 = phi i32 [ -2, %27 ], [ -1, %4 ], [ 0, %33 ], [ 0, %30 ]
ret i32 %37
}