#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ free(unsigned int *);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, unsigned int *, unsigned int);
int verify(int fd, unsigned int k) {
  unsigned int i;
  ssize_t bytes_read;
  unsigned int *buf = NULL;
  if ((buf = (unsigned int *)malloc(k * sizeof(unsigned int))) == NULL) {
    printf("READER: error from malloc\n");
    goto error;
  }
  if (lseek(fd, (off_t)0, SEEK_SET) < 0) {
    printf("READER: error from lseek\n");
    goto error;
  }
  if ((bytes_read = read(fd, buf, (k * sizeof(unsigned int)))) < 0) {
    printf("READER: error from read\n");
    goto error;
  }
  if (bytes_read != (ssize_t)(k * sizeof(unsigned int))) {
    printf("READER: error from bytes read=%lu\n", (unsigned long)bytes_read);
    goto error;
  }
  for (i = 0; i < k; i++) {
    if (buf[i] != i)
      break;
  }
  if (i < k) {
    if (buf[k - 1] != (i - 1)) {
      printf("FAIL IN READER: ...beginning sentinel value=%u, i=%u\n", (i - 1),
             i);
      printf("FAIL IN READER: buf[%u]=%u\n", i - 1, buf[i - 1]);
      printf("FAIL IN READER: buf[%u]=%u\n", i, buf[i]);
      printf("FAIL IN READER: buf[%u]=%u\n", i + 1, buf[i + 1]);
      printf("FAIL IN READER: ...ending sentinel value=%u\n", buf[k - 1]);
      goto error;
    }
  }
  if (buf)
    free(buf);
  return 0;
error:
  if (buf)
    free(buf);
  return -1;
}


x86 assembly (clang, -O0):
<verify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1195 <verify+0x45>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    134c <verify+0x1fc>
mov    -0x8(%rbp),%edi
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
cmp    $0x0,%rax
jge    11c5 <verify+0x75>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    134c <verify+0x1fc>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0xc(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edx
call   1060 <read@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    11fb <verify+0xab>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    134c <verify+0x1fc>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x2,%rcx
cmp    %rcx,%rax
je     1226 <verify+0xd6>
mov    -0x18(%rbp),%rsi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    134c <verify+0x1fc>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1264 <verify+0x114>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
cmp    -0x10(%rbp),%eax
je     1251 <verify+0x101>
jmp    1264 <verify+0x114>
jmp    1256 <verify+0x106>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    122d <verify+0xdd>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    132c <verify+0x1dc>
mov    -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,4),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1327 <verify+0x1d7>
mov    -0x10(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%edx
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
sub    $0x1,%esi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,4),%edx
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    (%rax,%rcx,4),%edx
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,4),%edx
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,4),%esi
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    134c <verify+0x1fc>
jmp    132c <verify+0x1dc>
cmpq   $0x0,-0x20(%rbp)
je     1340 <verify+0x1f0>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1367 <verify+0x217>
cmpq   $0x0,-0x20(%rbp)
je     1360 <verify+0x210>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    %esi,%r12d
lea    0x0(,%r12,4),%rbx
mov    %ebx,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     11d4 <verify+0x74>
mov    %rax,%r15
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
test   %rax,%rax
js     11e2 <verify+0x82>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1070 <read@plt>
test   %rax,%rax
js     11f0 <verify+0x90>
cmp    %rbx,%rax
jne    11fe <verify+0x9e>
test   %r14d,%r14d
je     1234 <verify+0xd4>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%eax
cmp    %rax,%rbx
jne    1225 <verify+0xc5>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11c0 <verify+0x60>
jmp    1234 <verify+0xd4>
lea    0xef8(%rip),%rdi
call   1040 <puts@plt>
jmp    1217 <verify+0xb7>
lea    0xed1(%rip),%rdi
call   1040 <puts@plt>
jmp    120f <verify+0xaf>
lea    0xeab(%rip),%rdi
call   1040 <puts@plt>
jmp    120f <verify+0xaf>
lea    0xdfb(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0xffffffff,%r14d
mov    (%r15,%r14,4),%eax
add    $0x1,%eax
cmp    %ebx,%eax
jne    1240 <verify+0xe0>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    121c <verify+0xbc>
lea    -0x1(%rbx),%rbp
lea    0xdd8(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
mov    (%r15,%rax,4),%edx
lea    0xdf6(%rip),%r12
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15,%rbx,4),%edx
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x1(%rbx),%esi
mov    0x4(%r15,%rbx,4),%edx
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15,%r14,4),%esi
lea    0xdd9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    120f <verify+0xaf>

LLVM IR (-O0):
@.str = [27 x i8] c"READER: error from malloc\0A\00"
@SEEK_SET = global i32 0
@.str.1 = [26 x i8] c"READER: error from lseek\0A\00"
@.str.2 = [25 x i8] c"READER: error from read\0A\00"
@.str.3 = [35 x i8] c"READER: error from bytes read=%lu\0A\00"
@.str.4 = [54 x i8] c"FAIL IN READER: ...beginning sentinel value=%u, i=%u\0A\00"
@.str.5 = [28 x i8] c"FAIL IN READER: buf[%u]=%u\0A\00"
@.str.6 = [45 x i8] c"FAIL IN READER: ...ending sentinel value=%u\0A\00"
define i32 @verify(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* null, i32** %8
%9 = load i32, i32* %5
%10 = zext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %8
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %122
18: ; preds = %2
%19 = load i32, i32* %4
%20 = load i32, i32* @SEEK_SET
%21 = call i64 @lseek(i32 %19, i32 0, i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %122
25: ; preds = %18
%26 = load i32, i32* %4
%27 = load i32*, i32** %8
%28 = load i32, i32* %5
%29 = zext i32 %28 to i64
%30 = mul i64 %29, 4
%31 = trunc i64 %30 to i32
%32 = call i64 @read(i32 %26, i32* %27, i32 %31)
store i64 %32, i64* %7
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %25
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %122
36: ; preds = %25
%37 = load i64, i64* %7
%38 = load i32, i32* %5
%39 = zext i32 %38 to i64
%40 = mul i64 %39, 4
%41 = icmp ne i64 %37, %40
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = load i64, i64* %7
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i64 %43)
br label %122
45: ; preds = %36
store i32 0, i32* %6
br label %46
46: ; preds = %60, %45
%47 = load i32, i32* %6
%48 = load i32, i32* %5
%49 = icmp ult i32 %47, %48
br i1 %49, label %50, label %63
50: ; preds = %46
%51 = load i32*, i32** %8
%52 = load i32, i32* %6
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
%55 = load i32, i32* %54
%56 = load i32, i32* %6
%57 = icmp ne i32 %55, %56
br i1 %57, label %58, label %59
58: ; preds = %50
br label %63
59: ; preds = %50
br label %60
60: ; preds = %59
%61 = load i32, i32* %6
%62 = add i32 %61, 1
store i32 %62, i32* %6
br label %46
63: ; preds = %58, %46
%64 = load i32, i32* %6
%65 = load i32, i32* %5
%66 = icmp ult i32 %64, %65
br i1 %66, label %67, label %115
67: ; preds = %63
%68 = load i32*, i32** %8
%69 = load i32, i32* %5
%70 = sub i32 %69, 1
%71 = zext i32 %70 to i64
%72 = getelementptr inbounds i32, i32* %68, i64 %71
%73 = load i32, i32* %72
%74 = load i32, i32* %6
%75 = sub i32 %74, 1
%76 = icmp ne i32 %73, %75
br i1 %76, label %77, label %114
77: ; preds = %67
%78 = load i32, i32* %6
%79 = sub i32 %78, 1
%80 = load i32, i32* %6
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i32 %79, i32 %80)
%82 = load i32, i32* %6
%83 = sub i32 %82, 1
%84 = load i32*, i32** %8
%85 = load i32, i32* %6
%86 = sub i32 %85, 1
%87 = zext i32 %86 to i64
%88 = getelementptr inbounds i32, i32* %84, i64 %87
%89 = load i32, i32* %88
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %83, i32 %89)
%91 = load i32, i32* %6
%92 = load i32*, i32** %8
%93 = load i32, i32* %6
%94 = zext i32 %93 to i64
%95 = getelementptr inbounds i32, i32* %92, i64 %94
%96 = load i32, i32* %95
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %91, i32 %96)
%98 = load i32, i32* %6
%99 = add i32 %98, 1
%100 = load i32*, i32** %8
%101 = load i32, i32* %6
%102 = add i32 %101, 1
%103 = zext i32 %102 to i64
%104 = getelementptr inbounds i32, i32* %100, i64 %103
%105 = load i32, i32* %104
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %99, i32 %105)
%107 = load i32*, i32** %8
%108 = load i32, i32* %5
%109 = sub i32 %108, 1
%110 = zext i32 %109 to i64
%111 = getelementptr inbounds i32, i32* %107, i64 %110
%112 = load i32, i32* %111
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i32 %112)
br label %122
114: ; preds = %67
br label %115
115: ; preds = %114, %63
%116 = load i32*, i32** %8
%117 = icmp ne i32* %116, null
br i1 %117, label %118, label %121
118: ; preds = %115
%119 = load i32*, i32** %8
%120 = call i32 @free(i32* %119)
br label %121
121: ; preds = %118, %115
store i32 0, i32* %3
br label %129
122: ; preds = %77, %42, %34, %23, %16
%123 = load i32*, i32** %8
%124 = icmp ne i32* %123, null
br i1 %124, label %125, label %128
125: ; preds = %122
%126 = load i32*, i32** %8
%127 = call i32 @free(i32* %126)
br label %128
128: ; preds = %125, %122
store i32 -1, i32* %3
br label %129
129: ; preds = %128, %121
%130 = load i32, i32* %3
ret i32 %130
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str.3 = [35 x i8] c"READER: error from bytes read=%lu\0A\00"
@.str.4 = [54 x i8] c"FAIL IN READER: ...beginning sentinel value=%u, i=%u\0A\00"
@.str.5 = [28 x i8] c"FAIL IN READER: buf[%u]=%u\0A\00"
@.str.6 = [45 x i8] c"FAIL IN READER: ...ending sentinel value=%u\0A\00"
@str = [24 x i8] c"READER: error from read\00"
@str.7 = [25 x i8] c"READER: error from lseek\00"
@str.8 = [26 x i8] c"READER: error from malloc\00"
define i32 @verify(i32 %0, i32 %1) {
%3 = zext i32 %1 to i64
%4 = shl nuw nsw i64 %3, 2
%5 = trunc i64 %4 to i32
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i32*
%8 = icmp eq i64 %6, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.8, i64 0, i64 0))
br label %66
11: ; preds = %2
%12 = load i32, i32* @SEEK_SET
%13 = tail call i64 @lseek(i32 %0, i32 0, i32 %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
br label %64
17: ; preds = %11
%18 = tail call i64 @read(i32 %0, i32* %7, i32 %5)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %64
22: ; preds = %17
%23 = icmp eq i64 %18, %4
br i1 %23, label %24, label %26
24: ; preds = %22
%25 = icmp eq i32 %1, 0
br i1 %25, label %45, label %28
26: ; preds = %22
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i64 %18)
br label %64
28: ; preds = %24, %34
%29 = phi i64 [ %35, %34 ], [ 0, %24 ]
%30 = getelementptr inbounds i32, i32* %7, i64 %29
%31 = load i32, i32* %30
%32 = zext i32 %31 to i64
%33 = icmp eq i64 %29, %32
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = add nuw nsw i64 %29, 1
%36 = icmp eq i64 %35, %3
br i1 %36, label %45, label %28
37: ; preds = %28
%38 = trunc i64 %29 to i32
%39 = add i32 %1, -1
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %7, i64 %40
%42 = load i32, i32* %41
%43 = add i32 %38, -1
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %47
45: ; preds = %34, %24, %37
%46 = tail call i32 @free(i32* %7)
br label %66
47: ; preds = %37
%48 = and i64 %29, 4294967295
%49 = getelementptr inbounds i32, i32* %7, i64 %48
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i32 %43, i32 %38)
%51 = zext i32 %43 to i64
%52 = getelementptr inbounds i32, i32* %7, i64 %51
%53 = load i32, i32* %52
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %43, i32 %53)
%55 = load i32, i32* %49
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %38, i32 %55)
%57 = add nuw i32 %38, 1
%58 = zext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %7, i64 %58
%60 = load i32, i32* %59
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %57, i32 %60)
%62 = load i32, i32* %41
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0), i32 %62)
br label %64
64: ; preds = %47, %15, %20, %26
%65 = tail call i32 @free(i32* %7)
br label %66
66: ; preds = %9, %64, %45
%67 = phi i32 [ 0, %45 ], [ -1, %64 ], [ -1, %9 ]
ret i32 %67
}