#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_SET;
int atoi(char *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("Usage: %s <RECORD FILE> <SKIP BYTES> <NO. of RECORDS>\n", argv[0]);
    return 1;
  }
  const char *path = argv[1];
  FILE *record = fopen(path, "r");
  int smem;
  int j = atoi(argv[3]);
  fseek(record, atoi(argv[2]), SEEK_SET);
  for (; j > 0; j--) {
    fread((void *)(&smem), 4, 1, record);
    printf("Smem value read is %x\n", smem);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1191 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1231 <main+0xe1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
cmpl   $0x0,-0x28(%rbp)
jle    122a <main+0xda>
lea    -0x24(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x24(%rbp),%esi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    11ea <main+0x9a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x3,%edi
jne    11df <main+0x8f>
mov    0x8(%r14),%rdi
lea    0xec9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    0x18(%r14),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%r14),%rdi
call   1070 <atoi@plt>
mov    0x2e4f(%rip),%rcx
mov    (%rcx),%edx
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <fseek@plt>
test   %ebp,%ebp
jle    11db <main+0x8b>
add    $0x1,%ebp
lea    0x4(%rsp),%r14
lea    0xe89(%rip),%r15
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    0x4(%rsp),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     11b0 <main+0x60>
xor    %eax,%eax
jmp    11f5 <main+0xa5>
mov    (%r14),%rsi
lea    0xe17(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [55 x i8] c"Usage: %s <RECORD FILE> <SKIP BYTES> <NO. of RECORDS>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.2 = [23 x i8] c"Smem value read is %x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %47
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %7
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 3
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %9
%27 = load i32*, i32** %7
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
%32 = load i32, i32* @SEEK_SET
%33 = call i32 @fseek(i32* %27, i32 %31, i32 %32)
br label %34
34: ; preds = %43, %17
%35 = load i32, i32* %9
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %34
%38 = bitcast i32* %8 to i8*
%39 = load i32*, i32** %7
%40 = call i32 @fread(i8* %38, i32 4, i32 1, i32* %39)
%41 = load i32, i32* %8
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %37
%44 = load i32, i32* %9
%45 = add nsw i32 %44, -1
store i32 %45, i32* %9
br label %34
46: ; preds = %34
store i32 0, i32* %3
br label %47
47: ; preds = %46, %12
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [55 x i8] c"Usage: %s <RECORD FILE> <SKIP BYTES> <NO. of RECORDS>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.2 = [23 x i8] c"Smem value read is %x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp eq i32 %0, 3
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %30
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = bitcast i32* %3 to i8*
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = load i32, i32* @SEEK_SET
%20 = tail call i32 @fseek(i32* %11, i32 %18, i32 %19)
%21 = icmp sgt i32 %15, 0
br i1 %21, label %22, label %29
22: ; preds = %8, %22
%23 = phi i32 [ %27, %22 ], [ %15, %8 ]
%24 = call i32 @fread(i8* %12, i32 4, i32 1, i32* %11)
%25 = load i32, i32* %3
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = add nsw i32 %23, -1
%28 = icmp ugt i32 %23, 1
br i1 %28, label %22, label %29
29: ; preds = %22, %8
br label %30
30: ; preds = %29, %5
%31 = phi i32 [ 1, %5 ], [ 0, %29 ]
ret i32 %31
}