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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ lseek(int, scalar_t__, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char **argv) {
  int my_file_desc;
  char file_name[4096];
  char read_buffer[4096];
  int i;
  int r;
  off_t offset;
  off_t where;
  if (argc < 3) {
    printf("need to specify a file name and an offset\n");
    exit(1);
  }
  for (i = 0; i < sizeof(file_name); i++) {
    file_name[i] = 0;
  }
  strncpy(file_name, argv[1], sizeof(file_name));
  file_name[sizeof(file_name) - 1] = 0;
  offset = (off_t)atoi(argv[2]);
  my_file_desc = open(file_name, O_RDONLY, 0);
  if (my_file_desc < 0) {
    printf("failed to open %s for reading\n", file_name);
    exit(1);
  }
  where = lseek(my_file_desc, offset, SEEK_SET);
  if (where < 0) {
    printf("lseek to %d in file %s failed\n", (int)offset, file_name);
    close(my_file_desc);
    exit(1);
  }
  for (i = 0; i < sizeof(read_buffer); i++) {
    read_buffer[i] = 0;
  }
  r = read(my_file_desc, read_buffer, sizeof(read_buffer) - 1);
  while (r > 0) {
    printf("%s", read_buffer);
    for (i = 0; i < sizeof(read_buffer); i++) {
      read_buffer[i] = 0;
    }
    r = read(my_file_desc, read_buffer, sizeof(read_buffer) - 1);
  }
  close(my_file_desc);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11bb <main+0x3b>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x2024(%rbp)
movslq -0x2024(%rbp),%rax
cmp    $0x1000,%rax
jae    11fb <main+0x7b>
movslq -0x2024(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
mov    -0x2024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2024(%rbp)
jmp    11c5 <main+0x45>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x1000,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x21(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %rax,-0x2030(%rbp)
lea    -0x1020(%rbp),%rdi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    126f <main+0xef>
lea    -0x1020(%rbp),%rsi
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x2030(%rbp),%rsi
mov    0x2d58(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
mov    %rax,-0x2038(%rbp)
cmpq   $0x0,-0x2038(%rbp)
jge    12cc <main+0x14c>
mov    -0x2030(%rbp),%rax
mov    %eax,%esi
lea    -0x1020(%rbp),%rdx
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x2024(%rbp)
movslq -0x2024(%rbp),%rax
cmp    $0x1000,%rax
jae    130c <main+0x18c>
movslq -0x2024(%rbp),%rax
movb   $0x0,-0x2020(%rbp,%rax,1)
mov    -0x2024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2024(%rbp)
jmp    12d6 <main+0x156>
mov    -0x14(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    $0xfff,%edx
call   1070 <read@plt>
mov    %eax,-0x2028(%rbp)
cmpl   $0x0,-0x2028(%rbp)
jle    13a7 <main+0x227>
lea    -0x2020(%rbp),%rsi
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x2024(%rbp)
movslq -0x2024(%rbp),%rax
cmp    $0x1000,%rax
jae    1388 <main+0x208>
movslq -0x2024(%rbp),%rax
movb   $0x0,-0x2020(%rbp,%rax,1)
mov    -0x2024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2024(%rbp)
jmp    1352 <main+0x1d2>
mov    -0x14(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    $0xfff,%edx
call   1070 <read@plt>
mov    %eax,-0x2028(%rbp)
jmp    1326 <main+0x1a6>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x2040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x2000,%rsp
cmp    $0x3,%edi
jl     12a4 <main+0x104>
mov    %rsi,%rbx
mov    %rsp,%rbp
mov    $0x1000,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    0x8(%rbx),%rsi
mov    %rbp,%rdi
mov    $0x1000,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xfff(%rsp)
mov    0x10(%rbx),%rdi
call   10b0 <atoi@plt>
mov    %rax,%r14
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
xor    %edx,%edx
call   10a0 <open@plt>
test   %eax,%eax
js     12ba <main+0x11a>
mov    %eax,%ebp
mov    0x2dc6(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %r14,%rsi
call   1060 <lseek@plt>
test   %rax,%rax
js     12d5 <main+0x135>
lea    0x1000(%rsp),%rbx
mov    $0x1000,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xfff,%edx
call   1090 <read@plt>
test   %eax,%eax
jle    128f <main+0xef>
lea    0xde6(%rip),%r14
lea    0x1000(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1000,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xfff,%edx
call   1090 <read@plt>
test   %eax,%eax
jg     1260 <main+0xc0>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x2000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd96(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xd3f(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xd43(%rip),%rdi
mov    %rsp,%rdx
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"need to specify a file name and an offset\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [31 x i8] c"failed to open %s for reading\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [31 x i8] c"lseek to %d in file %s failed\0A\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [4096 x i8]
%8 = alloca [4096 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
store i32 0, i32* %9
br label %19
19: ; preds = %27, %18
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = icmp ult i64 %21, 4096
br i1 %22, label %23, label %30
23: ; preds = %19
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %23
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
br label %19
30: ; preds = %19
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @strncpy(i8* %31, i8* %34, i32 4096)
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 4095
store i8 0, i8* %36
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i64 @atoi(i8* %39)
store i64 %40, i64* %11
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%42 = load i32, i32* @O_RDONLY
%43 = call i32 @open(i8* %41, i32 %42, i32 0)
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %30
%47 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %30
%51 = load i32, i32* %6
%52 = load i64, i64* %11
%53 = load i32, i32* @SEEK_SET
%54 = call i64 @lseek(i32 %51, i64 %52, i32 %53)
store i64 %54, i64* %12
%55 = load i64, i64* %12
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %65
57: ; preds = %50
%58 = load i64, i64* %11
%59 = trunc i64 %58 to i32
%60 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %59, i8* %60)
%62 = load i32, i32* %6
%63 = call i32 @close(i32 %62)
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %50
store i32 0, i32* %9
br label %66
66: ; preds = %74, %65
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
%69 = icmp ult i64 %68, 4096
br i1 %69, label %70, label %77
70: ; preds = %66
%71 = load i32, i32* %9
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %72
store i8 0, i8* %73
br label %74
74: ; preds = %70
%75 = load i32, i32* %9
%76 = add nsw i32 %75, 1
store i32 %76, i32* %9
br label %66
77: ; preds = %66
%78 = load i32, i32* %6
%79 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%80 = call i32 @read(i32 %78, i8* %79, i32 4095)
store i32 %80, i32* %10
br label %81
81: ; preds = %98, %77
%82 = load i32, i32* %10
%83 = icmp sgt i32 %82, 0
br i1 %83, label %84, label %102
84: ; preds = %81
%85 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %85)
store i32 0, i32* %9
br label %87
87: ; preds = %95, %84
%88 = load i32, i32* %9
%89 = sext i32 %88 to i64
%90 = icmp ult i64 %89, 4096
br i1 %90, label %91, label %98
91: ; preds = %87
%92 = load i32, i32* %9
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %93
store i8 0, i8* %94
br label %95
95: ; preds = %91
%96 = load i32, i32* %9
%97 = add nsw i32 %96, 1
store i32 %97, i32* %9
br label %87
98: ; preds = %87
%99 = load i32, i32* %6
%100 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%101 = call i32 @read(i32 %99, i8* %100, i32 4095)
store i32 %101, i32* %10
br label %81
102: ; preds = %81
%103 = load i32, i32* %6
%104 = call i32 @close(i32 %103)
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str.1 = [31 x i8] c"failed to open %s for reading\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [31 x i8] c"lseek to %d in file %s failed\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@str = [42 x i8] c"need to specify a file name and an offset\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%8 = icmp slt i32 %0, 3
br i1 %8, label %21, label %9
9: ; preds = %2
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @strncpy(i8* %6, i8* %12, i32 4096)
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 4095
store i8 0, i8* %14
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = call i64 @atoi(i8* %16)
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @open(i8* %6, i32 %18, i32 0)
%20 = icmp slt i32 %19, 0
br i1 %20, label %24, label %27
21: ; preds = %2
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %9
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %9
%28 = load i32, i32* @SEEK_SET
%29 = call i64 @lseek(i32 %19, i64 %17, i32 %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = call i32 @read(i32 %19, i8* %7, i32 4095)
%33 = icmp sgt i32 %32, 0
br i1 %33, label %39, label %43
34: ; preds = %27
%35 = trunc i64 %17 to i32
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %35, i8* %6)
%37 = call i32 @close(i32 %19)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %31, %39
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%41 = call i32 @read(i32 %19, i8* %7, i32 4095)
%42 = icmp sgt i32 %41, 0
br i1 %42, label %39, label %43
43: ; preds = %39, %31
%44 = call i32 @close(i32 %19)
ret i32 0
}