#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 ssize_t;
typedef scalar_t__ off_t;

/* Variables and functions */
scalar_t__ EINTR;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int SEEK_END;
int SEEK_SET;
int /*<<< orphan*/ STDOUT_FILENO;
scalar_t__ atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ lseek(int, scalar_t__, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  int fd;
  char buf[1024];
  ssize_t ret;
  char *devfile;
  char *set_end;
  off_t ofs;
  char *usage = "usage: cats <in file> <SET|END> <seek bytes>";
  int whence = 0;
  if (argc != 4) {
    fprintf(stderr, "%s\n", usage);
    exit(1);
  }
  devfile = argv[1];
  set_end = argv[2];
  ofs = atoi(argv[3]);
  fd = open(devfile, O_RDONLY);
  if (-1 == fd) {
    perror("open()");
    return EXIT_FAILURE;
  }
  if (0 == strcmp(set_end, "SET")) {
    whence = SEEK_SET;
  } else if (0 == strcmp(set_end, "END")) {
    whence = SEEK_END;
  } else {
    fprintf(stderr, "unknown seek type '%s'\n", set_end);
    fprintf(stderr, "%s\n", usage);
    exit(1);
  }
  ofs = lseek(fd, ofs, whence);
  if ((off_t)-1 == ofs) {
    perror("lseek()");
    return EXIT_FAILURE;
  }
  while ((ret = read(fd, buf, 1024))) {
    if (errno == EINTR) {
      continue;
    } else if (-1 == ret) {
      perror("read()");
      return EXIT_FAILURE;
    }
    write(STDOUT_FILENO, buf, ret);
  }
  close(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe40(%rip),%rax
mov    %rax,-0x448(%rbp)
movl   $0x0,-0x44c(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1201 <main+0x61>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    -0x448(%rbp),%rdx
lea    0xe3b(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x430(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x438(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10b0 <atoi@plt>
mov    %rax,-0x440(%rbp)
mov    -0x430(%rbp),%rdi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    1276 <main+0xd6>
lea    0xdd1(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1422 <main+0x282>
mov    -0x438(%rbp),%rdi
lea    0xdb4(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12ab <main+0x10b>
mov    0x2d1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44c(%rbp)
jmp    1327 <main+0x187>
mov    -0x438(%rbp),%rdi
lea    0xd83(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12e0 <main+0x140>
mov    0x2d0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44c(%rbp)
jmp    1322 <main+0x182>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
mov    -0x438(%rbp),%rdx
lea    0xd49(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
mov    -0x448(%rbp),%rdx
lea    0xd1a(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    1327 <main+0x187>
mov    -0x14(%rbp),%edi
mov    -0x440(%rbp),%rsi
mov    -0x44c(%rbp),%edx
call   1040 <lseek@plt>
mov    %rax,-0x440(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    -0x440(%rbp),%rax
jne    1374 <main+0x1d4>
lea    0xcfa(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1422 <main+0x282>
jmp    1379 <main+0x1d9>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
je     140e <main+0x26e>
mov    0x2c1d(%rip),%rax
mov    (%rax),%rax
mov    0x2bfb(%rip),%rcx
cmp    (%rcx),%rax
jne    13bb <main+0x21b>
jmp    1379 <main+0x1d9>
mov    $0xffffffff,%eax
cmp    -0x424(%rbp),%eax
jne    13e9 <main+0x249>
lea    0xc8d(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2bd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1422 <main+0x282>
jmp    13ee <main+0x24e>
mov    0x2bfb(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rsi
mov    -0x424(%rbp),%edx
call   1030 <write@plt>
jmp    1379 <main+0x1d9>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    0x2b83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
cmp    $0x4,%edi
jne    12e5 <main+0x145>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%r15
mov    0x18(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %rax,%r14
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     12c7 <main+0x127>
mov    %eax,%ebp
lea    0xe49(%rip),%rsi
mov    %r15,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     121d <main+0x7d>
lea    0xe39(%rip),%rsi
mov    %r15,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    12f0 <main+0x150>
mov    0x2dc5(%rip),%rax
jmp    1224 <main+0x84>
mov    0x2d94(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <lseek@plt>
cmp    $0xffffffffffffffff,%rax
je     12d0 <main+0x130>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x400,%edx
call   1060 <read@plt>
test   %eax,%eax
je     12a7 <main+0x107>
mov    0x2d6c(%rip),%r14
mov    0x2d4d(%rip),%r15
mov    %rsp,%rbx
mov    0x2d8b(%rip),%r12
jmp    1291 <main+0xf1>
nopw   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
test   %eax,%eax
je     12a7 <main+0x107>
mov    (%r14),%rcx
cmp    (%r15),%rcx
je     127e <main+0xde>
cmp    $0xffffffff,%eax
jne    1270 <main+0xd0>
lea    0xdbb(%rip),%rdi
jmp    12d7 <main+0x137>
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd63(%rip),%rdi
jmp    12d7 <main+0x137>
lea    0xd81(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2ccd(%rip),%rax
jmp    12b5 <main+0x115>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
jmp    130a <main+0x16a>
mov    0x2cd1(%rip),%rbx
mov    (%rbx),%edi
lea    0xd40(%rip),%rsi
mov    %r15,%rdx
call   1080 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd1c(%rip),%rsi
lea    0xce8(%rip),%rdx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"usage: cats <in file> <SET|END> <seek bytes>\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [7 x i8] c"open()\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"SET\00"
@SEEK_SET = global i32 0
@.str.4 = [4 x i8] c"END\00"
@SEEK_END = global i32 0
@.str.5 = [24 x i8] c"unknown seek type '%s'\0A\00"
@.str.6 = [8 x i8] c"lseek()\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.7 = [7 x i8] c"read()\00"
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8** %12
store i32 0, i32* %13
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 4
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %9
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
store i8* %27, i8** %10
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 3
%30 = load i8*, i8** %29
%31 = call i64 @atoi(i8* %30)
store i64 %31, i64* %11
%32 = load i8*, i8** %9
%33 = load i32, i32* @O_RDONLY
%34 = call i32 @open(i8* %32, i32 %33)
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = icmp eq i32 -1, %35
br i1 %36, label %37, label %40
37: ; preds = %21
%38 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
store i32 %39, i32* %3
br label %98
40: ; preds = %21
%41 = load i8*, i8** %10
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%43 = icmp eq i64 0, %42
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = load i32, i32* @SEEK_SET
store i32 %45, i32* %13
br label %61
46: ; preds = %40
%47 = load i8*, i8** %10
%48 = call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%49 = icmp eq i64 0, %48
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = load i32, i32* @SEEK_END
store i32 %51, i32* %13
br label %60
52: ; preds = %46
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %10
%55 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %54)
%56 = load i32, i32* @stderr
%57 = load i8*, i8** %12
%58 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %50
br label %61
61: ; preds = %60, %44
%62 = load i32, i32* %6
%63 = load i64, i64* %11
%64 = load i32, i32* %13
%65 = call i64 @lseek(i32 %62, i64 %63, i32 %64)
store i64 %65, i64* %11
%66 = load i64, i64* %11
%67 = icmp eq i64 -1, %66
br i1 %67, label %68, label %71
68: ; preds = %61
%69 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%70 = load i32, i32* @EXIT_FAILURE
store i32 %70, i32* %3
br label %98
71: ; preds = %61
br label %72
72: ; preds = %89, %81, %71
%73 = load i32, i32* %6
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%75 = call i32 @read(i32 %73, i8* %74, i32 1024)
store i32 %75, i32* %8
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %94
77: ; preds = %72
%78 = load i64, i64* @errno
%79 = load i64, i64* @EINTR
%80 = icmp eq i64 %78, %79
br i1 %80, label %81, label %82
81: ; preds = %77
br label %72
82: ; preds = %77
%83 = load i32, i32* %8
%84 = icmp eq i32 -1, %83
br i1 %84, label %85, label %88
85: ; preds = %82
%86 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%87 = load i32, i32* @EXIT_FAILURE
store i32 %87, i32* %3
br label %98
88: ; preds = %82
br label %89
89: ; preds = %88
%90 = load i32, i32* @STDOUT_FILENO
%91 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%92 = load i32, i32* %8
%93 = call i32 @write(i32 %90, i8* %91, i32 %92)
br label %72
94: ; preds = %72
%95 = load i32, i32* %6
%96 = call i32 @close(i32 %95)
%97 = load i32, i32* @EXIT_SUCCESS
store i32 %97, i32* %3
br label %98
98: ; preds = %94, %85, %68, %37
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
@.str = [45 x i8] c"usage: cats <in file> <SET|END> <seek bytes>\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [7 x i8] c"open()\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"SET\00"
@SEEK_SET = global i32 0
@.str.4 = [4 x i8] c"END\00"
@SEEK_END = global i32 0
@.str.5 = [24 x i8] c"unknown seek type '%s'\0A\00"
@.str.6 = [8 x i8] c"lseek()\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.7 = [7 x i8] c"read()\00"
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = global i32 0
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 %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = tail call i64 @atoi(i8* %16)
%18 = load i32, i32* @O_RDONLY
%19 = tail call i32 @open(i8* %12, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %10
%22 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %62
23: ; preds = %10
%24 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %35, label %26
26: ; preds = %23
%27 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %35, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %14)
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %26, %23
%36 = phi i32* [ @SEEK_SET, %23 ], [ @SEEK_END, %26 ]
%37 = load i32, i32* %36
%38 = tail call i64 @lseek(i32 %19, i64 %17, i32 %37)
%39 = icmp eq i64 %38, -1
br i1 %39, label %43, label %40
40: ; preds = %35
%41 = call i32 @read(i32 %19, i8* %4, i32 1024)
%42 = icmp eq i32 %41, 0
br i1 %42, label %60, label %45
43: ; preds = %35
%44 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %62
45: ; preds = %40, %57
%46 = phi i32 [ %58, %57 ], [ %41, %40 ]
%47 = load i64, i64* @errno
%48 = load i64, i64* @EINTR
%49 = icmp eq i64 %47, %48
br i1 %49, label %57, label %50
50: ; preds = %45
%51 = icmp eq i32 %46, -1
br i1 %51, label %52, label %54
52: ; preds = %50
%53 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %62
54: ; preds = %50
%55 = load i32, i32* @STDOUT_FILENO
%56 = call i32 @write(i32 %55, i8* %4, i32 %46)
br label %57
57: ; preds = %54, %45
%58 = call i32 @read(i32 %19, i8* %4, i32 1024)
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %45
60: ; preds = %57, %40
%61 = tail call i32 @close(i32 %19)
br label %62
62: ; preds = %60, %52, %43, %21
%63 = phi i32* [ @EXIT_FAILURE, %21 ], [ @EXIT_FAILURE, %43 ], [ @EXIT_FAILURE, %52 ], [ @EXIT_SUCCESS, %60 ]
%64 = load i32, i32* %63
ret i32 %64
}