#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  int err = 0;
  FILE *fp = 0;
  int byteCount = 0;
  int iterCount = 0;
  char dataArray[1024];
  if (argc != 4) {
    printf("Error: No of argumets not proper\n");
    return 0;
  }
  byteCount = atoi(argv[2]);
  iterCount = atoi(argv[3]);
  fp = fopen(argv[1], "r");
  if (fp == NULL) {
    printf("Error: Invalid device name passed\n");
    return 0;
  }
  srand((unsigned int)time(NULL));
  while (iterCount != 0) {
    err = fread(dataArray, 1, byteCount, fp);
    if (err < 0) {
      printf("Error: Data read failed\n");
      return 0;
    }
    fseek(fp, ((iterCount % 5) * 100 * 1024), SEEK_SET);
    if (err < 0) {
      printf("Error: Data seek failed\n");
      return 0;
    }
    err = fread(dataArray, 1, byteCount, fp);
    if (err < 0) {
      printf("Error: Data read failed\n");
      return 0;
    }
    fseek(fp, byteCount, SEEK_END);
    if (err < 0) {
      printf("Error: Data seek failed\n");
      return 0;
    }
    err = fread(dataArray, 1, byteCount, fp);
    if (err < 0) {
      printf("Error: Data read failed\n");
      return 0;
    }
    rewind(fp);
    iterCount--;
    fclose(fp);
    usleep(((rand() % 50) + 1) * 1000);
    fp = fopen(argv[1], "r");
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1208 <main+0x58>
lea    0xe09(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1415 <main+0x265>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdeb(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1263 <main+0xb3>
lea    0xdd2(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1415 <main+0x265>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
cmpl   $0x0,-0x28(%rbp)
je     1405 <main+0x255>
lea    -0x430(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12ba <main+0x10a>
lea    0xd9e(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1415 <main+0x265>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
imul   $0x64,%edx,%esi
shl    $0xa,%esi
mov    0x2d02(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
cmpl   $0x0,-0x14(%rbp)
jge    12ff <main+0x14f>
lea    0xd72(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1415 <main+0x265>
lea    -0x430(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    133c <main+0x18c>
lea    0xd1c(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1415 <main+0x265>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    0x2c9e(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
cmpl   $0x0,-0x14(%rbp)
jge    1373 <main+0x1c3>
lea    0xcfe(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1415 <main+0x265>
lea    -0x430(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    13b0 <main+0x200>
lea    0xca8(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1415 <main+0x265>
mov    -0x20(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x0,%al
call   10c0 <rand@plt>
mov    $0x32,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
imul   $0x3e8,%edx,%edi
call   10d0 <usleep@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc2b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
jmp    1273 <main+0xc3>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
cmp    $0x4,%edi
jne    1318 <main+0x168>
mov    %rsi,%r14
mov    0x10(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r13d
mov    0x18(%r14),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebx
mov    0x8(%r14),%rdi
lea    0xe6a(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1321 <main+0x171>
mov    %rax,%rbp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
test   %ebx,%ebx
je     130e <main+0x15e>
mov    %rsp,%r15
mov    0x2db8(%rip),%r12
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
test   %eax,%eax
js     132a <main+0x17a>
movslq %ebx,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
imul   $0x19000,%eax,%esi
mov    (%r12),%edx
mov    %rbp,%rdi
call   1090 <fseek@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
test   %eax,%eax
js     132a <main+0x17a>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    %r13d,%esi
call   1090 <fseek@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
test   %eax,%eax
js     132a <main+0x17a>
mov    %rbp,%rdi
call   1060 <rewind@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
call   10c0 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x24,%rcx
add    %edx,%ecx
imul   $0x32,%ecx,%ecx
sub    %ecx,%eax
imul   $0x3e8,%eax,%edi
add    $0x3e8,%edi
call   10d0 <usleep@plt>
mov    0x8(%r14),%rdi
lea    0xd5c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbp
add    $0xffffffff,%ebx
jne    1220 <main+0x70>
mov    %rbp,%rdi
call   1050 <fclose@plt>
jmp    1336 <main+0x186>
lea    0xd1b(%rip),%rdi
jmp    1331 <main+0x181>
lea    0xcf0(%rip),%rdi
jmp    1331 <main+0x181>
lea    0xccf(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Error: No of argumets not proper\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [35 x i8] c"Error: Invalid device name passed\0A\00"
@.str.3 = [25 x i8] c"Error: Data read failed\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [25 x i8] c"Error: Data seek failed\0A\00"
@SEEK_END = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32* null, i32** %7
store i32 0, i32* %8
store i32 0, i32* %9
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %106
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %8
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %9
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %7
%28 = load i32*, i32** %7
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %15
%31 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %106
32: ; preds = %15
%33 = call i64 @time(i32* null)
%34 = trunc i64 %33 to i32
%35 = call i32 @srand(i32 %34)
br label %36
36: ; preds = %87, %32
%37 = load i32, i32* %9
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %103
39: ; preds = %36
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%41 = load i32, i32* %8
%42 = load i32*, i32** %7
%43 = call i32 @fread(i8* %40, i32 1, i32 %41, i32* %42)
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %106
48: ; preds = %39
%49 = load i32*, i32** %7
%50 = load i32, i32* %9
%51 = srem i32 %50, 5
%52 = mul nsw i32 %51, 100
%53 = mul nsw i32 %52, 1024
%54 = load i32, i32* @SEEK_SET
%55 = call i32 @fseek(i32* %49, i32 %53, i32 %54)
%56 = load i32, i32* %6
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %48
%59 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %106
60: ; preds = %48
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%62 = load i32, i32* %8
%63 = load i32*, i32** %7
%64 = call i32 @fread(i8* %61, i32 1, i32 %62, i32* %63)
store i32 %64, i32* %6
%65 = load i32, i32* %6
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %60
%68 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %106
69: ; preds = %60
%70 = load i32*, i32** %7
%71 = load i32, i32* %8
%72 = load i32, i32* @SEEK_END
%73 = call i32 @fseek(i32* %70, i32 %71, i32 %72)
%74 = load i32, i32* %6
%75 = icmp slt i32 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %69
%77 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %106
78: ; preds = %69
%79 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%80 = load i32, i32* %8
%81 = load i32*, i32** %7
%82 = call i32 @fread(i8* %79, i32 1, i32 %80, i32* %81)
store i32 %82, i32* %6
%83 = load i32, i32* %6
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %78
%86 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %106
87: ; preds = %78
%88 = load i32*, i32** %7
%89 = call i32 @rewind(i32* %88)
%90 = load i32, i32* %9
%91 = add nsw i32 %90, -1
store i32 %91, i32* %9
%92 = load i32*, i32** %7
%93 = call i32 @fclose(i32* %92)
%94 = call i32 (...) @rand()
%95 = srem i32 %94, 50
%96 = add nsw i32 %95, 1
%97 = mul nsw i32 %96, 1000
%98 = call i32 @usleep(i32 %97)
%99 = load i8**, i8*** %5
%100 = getelementptr inbounds i8*, i8** %99, i64 1
%101 = load i8*, i8** %100
%102 = call i32* @fopen(i8* %101, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %102, i32** %7
br label %36
103: ; preds = %36
%104 = load i32*, i32** %7
%105 = call i32 @fclose(i32* %104)
store i32 0, i32* %3
br label %106
106: ; preds = %103, %85, %76, %67, %58, %46, %30, %13
%107 = load i32, i32* %3
ret i32 %107
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@SEEK_END = global i32 0
@str.6 = [24 x i8] c"Error: Data read failed\00"
@str.7 = [34 x i8] c"Error: Invalid device name passed\00"
@str.8 = [33 x i8] c"Error: No of argumets not proper\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 4
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.8, i64 0, i64 0))
br label %64
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 3
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %8
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.7, i64 0, i64 0))
br label %64
21: ; preds = %8
%22 = tail call i64 @time(i32* null)
%23 = trunc i64 %22 to i32
%24 = tail call i32 @srand(i32 %23)
%25 = icmp eq i32 %14, 0
br i1 %25, label %61, label %26
26: ; preds = %21, %49
%27 = phi i32 [ %51, %49 ], [ %14, %21 ]
%28 = phi i32* [ %59, %49 ], [ %17, %21 ]
%29 = call i32 @fread(i8* %4, i32 1, i32 %11, i32* %28)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.6, i64 0, i64 0))
br label %64
33: ; preds = %26
%34 = srem i32 %27, 5
%35 = mul nsw i32 %34, 102400
%36 = load i32, i32* @SEEK_SET
%37 = tail call i32 @fseek(i32* %28, i32 %35, i32 %36)
%38 = call i32 @fread(i8* %4, i32 1, i32 %11, i32* %28)
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %33
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.6, i64 0, i64 0))
br label %64
42: ; preds = %33
%43 = load i32, i32* @SEEK_END
%44 = tail call i32 @fseek(i32* %28, i32 %11, i32 %43)
%45 = call i32 @fread(i8* %4, i32 1, i32 %11, i32* %28)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.6, i64 0, i64 0))
br label %64
49: ; preds = %42
%50 = tail call i32 @rewind(i32* %28)
%51 = add nsw i32 %27, -1
%52 = tail call i32 @fclose(i32* %28)
%53 = tail call i32 (...) @rand()
%54 = srem i32 %53, 50
%55 = mul nsw i32 %54, 1000
%56 = add nsw i32 %55, 1000
%57 = tail call i32 @usleep(i32 %56)
%58 = load i8*, i8** %15
%59 = tail call i32* @fopen(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%60 = icmp eq i32 %51, 0
br i1 %60, label %61, label %26
61: ; preds = %49, %21
%62 = phi i32* [ %17, %21 ], [ %59, %49 ]
%63 = tail call i32 @fclose(i32* %62)
br label %64
64: ; preds = %61, %47, %40, %31, %19, %6
ret i32 0
}