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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, int *, int);
int write(int, int *, int);
int main() {
  int j, length, fd, rc;
  int vector[2122];
  off_t offset;
  length = sizeof(int) * 2122;
  offset = sizeof(int) * 250;
  fd = open("/dev/mybdrv", O_RDWR);
  for (j = 0; j < 2122; j++) {
    vector[j] = j;
  }
  rc = write(fd, vector, length);
  printf("\n **** return code from write = %d\n", rc);
  rc = lseek(fd, offset, SEEK_SET);
  printf("\n **** retrun code from lseek(%d) = %d \n", (int)offset, rc);
  rc = read(fd, vector + 250, sizeof(int));
  printf("\n **** retrun code from read vec[%d] = %d, vec[%d] = %d \n", 250, rc,
         250, vector[250]);
  close(fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2150,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2128,-0xc(%rbp)
movl   $0x3e8,-0x2144(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
lea    0xe5d(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x84a,-0x8(%rbp)
jge    11db <main+0x6b>
mov    -0x8(%rbp),%ecx
movslq -0x8(%rbp),%rax
mov    %ecx,-0x2140(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b2 <main+0x42>
mov    -0x10(%rbp),%edi
lea    -0x2140(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%edi
mov    -0x2144(%rbp),%esi
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
mov    %eax,-0x14(%rbp)
mov    -0x2144(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%edi
lea    -0x2140(%rbp),%rsi
add    $0x3e8,%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edx
mov    -0x1d58(%rbp),%r8d
lea    0xdf8(%rip),%rdi
mov    $0xfa,%ecx
mov    %ecx,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x2130,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xf28(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
movdqa 0xe69(%rip),%xmm0
mov    $0x24,%eax
movdqa 0xe6b(%rip),%xmm8
movdqa 0xe72(%rip),%xmm9
movdqa 0xe79(%rip),%xmm10
movdqa 0xe80(%rip),%xmm11
movdqa 0xe87(%rip),%xmm12
movdqa 0xe8f(%rip),%xmm6
movdqa 0xe97(%rip),%xmm7
movdqa 0xe9f(%rip),%xmm1
movdqa 0xea7(%rip),%xmm2
movdqa 0xeaf(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm4
paddd  %xmm8,%xmm4
movdqa %xmm0,-0x90(%rsp,%rax,4)
ff ff
movdqa %xmm4,-0x80(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm9,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm10,%xmm5
movdqa %xmm4,-0x70(%rsp,%rax,4)
movdqa %xmm5,-0x60(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm11,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm12,%xmm5
movdqa %xmm4,-0x50(%rsp,%rax,4)
movdqa %xmm5,-0x40(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm6,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm7,%xmm5
movdqa %xmm4,-0x30(%rsp,%rax,4)
movdqa %xmm5,-0x20(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm1,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqa %xmm4,-0x10(%rsp,%rax,4)
movdqa %xmm5,(%rsp,%rax,4)
paddd  %xmm3,%xmm0
add    $0x28,%rax
cmp    $0x86c,%rax
jne    1200 <main+0x90>
movabs $0x84900000848,%rax
mov    %rax,0x2120(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x2128,%edx
call   1030 <write@plt>
lea    0xdf5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d01(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x3e8,%esi
call   1050 <lseek@plt>
lea    0xdf4(%rip),%rdi
mov    $0x3e8,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x3e8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1070 <read@plt>
mov    0x3e8(%rsp),%r8d
lea    0xdec(%rip),%rdi
mov    $0xfa,%esi
mov    %eax,%edx
mov    $0xfa,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/mybdrv\00"
@O_RDWR = global i32 0
@.str.1 = [36 x i8] c"\0A **** return code from write = %d\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [41 x i8] c"\0A **** retrun code from lseek(%d) = %d \0A\00"
@.str.3 = [58 x i8] c"\0A **** retrun code from read vec[%d] = %d, vec[%d] = %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2122 x i32]
%7 = alloca i32
store i32 0, i32* %1
store i32 8488, i32* %3
store i32 1000, i32* %7
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %4
store i32 0, i32* %2
br label %10
10: ; preds = %18, %0
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 2122
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load i32, i32* %2
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [2122 x i32], [2122 x i32]* %6, i64 0, i64 %16
store i32 %14, i32* %17
br label %18
18: ; preds = %13
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %10
21: ; preds = %10
%22 = load i32, i32* %4
%23 = getelementptr inbounds [2122 x i32], [2122 x i32]* %6, i64 0, i64 0
%24 = load i32, i32* %3
%25 = call i32 @write(i32 %22, i32* %23, i32 %24)
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %4
%29 = load i32, i32* %7
%30 = load i32, i32* @SEEK_SET
%31 = call i32 @lseek(i32 %28, i32 %29, i32 %30)
store i32 %31, i32* %5
%32 = load i32, i32* %7
%33 = load i32, i32* %5
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %32, i32 %33)
%35 = load i32, i32* %4
%36 = getelementptr inbounds [2122 x i32], [2122 x i32]* %6, i64 0, i64 0
%37 = getelementptr inbounds i32, i32* %36, i64 250
%38 = call i32 @read(i32 %35, i32* %37, i32 4)
store i32 %38, i32* %5
%39 = load i32, i32* %5
%40 = getelementptr inbounds [2122 x i32], [2122 x i32]* %6, i64 0, i64 250
%41 = load i32, i32* %40
%42 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i32 250, i32 %39, i32 250, i32 %41)
%43 = load i32, i32* %4
%44 = call i32 @close(i32 %43)
%45 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/mybdrv\00"
@O_RDWR = global i32 0
@.str.1 = [36 x i8] c"\0A **** return code from write = %d\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [41 x i8] c"\0A **** retrun code from lseek(%d) = %d \0A\00"
@.str.3 = [58 x i8] c"\0A **** retrun code from read vec[%d] = %d, vec[%d] = %d \0A\00"
define i32 @main() {
%1 = alloca [2122 x i32]
%2 = bitcast [2122 x i32]* %1 to i8*
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %5
5: ; preds = %5, %0
%6 = phi i64 [ 0, %0 ], [ %41, %5 ]
%7 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %42, %5 ]
%8 = add <4 x i32> %7, <i32 4, i32 4, i32 4, i32 4>
%9 = getelementptr inbounds [2122 x i32], [2122 x i32]* %1, i64 0, i64 %6
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> %7, <4 x i32>* %10
%11 = getelementptr inbounds i32, i32* %9, i64 4
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> %8, <4 x i32>* %12
%13 = add nuw nsw i64 %6, 8
%14 = add <4 x i32> %7, <i32 8, i32 8, i32 8, i32 8>
%15 = add <4 x i32> %7, <i32 12, i32 12, i32 12, i32 12>
%16 = getelementptr inbounds [2122 x i32], [2122 x i32]* %1, i64 0, i64 %13
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> %14, <4 x i32>* %17
%18 = getelementptr inbounds i32, i32* %16, i64 4
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> %15, <4 x i32>* %19
%20 = add nuw nsw i64 %6, 16
%21 = add <4 x i32> %7, <i32 16, i32 16, i32 16, i32 16>
%22 = add <4 x i32> %7, <i32 20, i32 20, i32 20, i32 20>
%23 = getelementptr inbounds [2122 x i32], [2122 x i32]* %1, i64 0, i64 %20
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> %21, <4 x i32>* %24
%25 = getelementptr inbounds i32, i32* %23, i64 4
%26 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> %22, <4 x i32>* %26
%27 = add nuw nsw i64 %6, 24
%28 = add <4 x i32> %7, <i32 24, i32 24, i32 24, i32 24>
%29 = add <4 x i32> %7, <i32 28, i32 28, i32 28, i32 28>
%30 = getelementptr inbounds [2122 x i32], [2122 x i32]* %1, i64 0, i64 %27
%31 = bitcast i32* %30 to <4 x i32>*
store <4 x i32> %28, <4 x i32>* %31
%32 = getelementptr inbounds i32, i32* %30, i64 4
%33 = bitcast i32* %32 to <4 x i32>*
store <4 x i32> %29, <4 x i32>* %33
%34 = add nuw nsw i64 %6, 32
%35 = add <4 x i32> %7, <i32 32, i32 32, i32 32, i32 32>
%36 = add <4 x i32> %7, <i32 36, i32 36, i32 36, i32 36>
%37 = getelementptr inbounds [2122 x i32], [2122 x i32]* %1, i64 0, i64 %34
%38 = bitcast i32* %37 to <4 x i32>*
store <4 x i32> %35, <4 x i32>* %38
%39 = getelementptr inbounds i32, i32* %37, i64 4
%40 = bitcast i32* %39 to <4 x i32>*
store <4 x i32> %36, <4 x i32>* %40
%41 = add nuw nsw i64 %6, 40
%42 = add <4 x i32> %7, <i32 40, i32 40, i32 40, i32 40>
%43 = icmp eq i64 %41, 2120
br i1 %43, label %44, label %5
44: ; preds = %5
%45 = getelementptr inbounds [2122 x i32], [2122 x i32]* %1, i64 0, i64 2120
store i32 2120, i32* %45
%46 = getelementptr inbounds [2122 x i32], [2122 x i32]* %1, i64 0, i64 2121
store i32 2121, i32* %46
%47 = getelementptr inbounds [2122 x i32], [2122 x i32]* %1, i64 0, i64 0
%48 = call i32 @write(i32 %4, i32* %47, i32 8488)
%49 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = load i32, i32* @SEEK_SET
%51 = tail call i32 @lseek(i32 %4, i32 1000, i32 %50)
%52 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 1000, i32 %51)
%53 = getelementptr inbounds [2122 x i32], [2122 x i32]* %1, i64 0, i64 250
%54 = call i32 @read(i32 %4, i32* %53, i32 4)
%55 = load i32, i32* %53
%56 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i32 250, i32 %54, i32 250, i32 %55)
%57 = tail call i32 @close(i32 %4)
%58 = tail call i32 @exit(i32 0)
unreachable
}