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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int errno;
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ pread(int, char *, int, int);
int /*<<< orphan*/ printf(char *, char const *, int);
int main(int argc, char *argv[]) {
  const char *sysctl;
  int offset;
  int fd;
  ssize_t len;
  char buffer[16];
  if (argc != 3) {
    return 77;
  }
  sysctl = argv[1];
  offset = atoi(argv[2]);
  fd = open(sysctl, O_RDONLY);
  if (fd < 0) {
    perror("Failed to open sysctl");
    return 77;
  }
  printf("Reading from '%s' at offset %d\n", sysctl, offset);
  len = pread(fd, buffer, 1, offset);
  if (len < 0) {
    perror("Read failed");
    return errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     117c <main+0x2c>
movl   $0x4d,-0x4(%rbp)
jmp    1229 <main+0xd9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11cf <main+0x7f>
lea    0xe42(%rip),%rdi
call   1050 <perror@plt>
movl   $0x4d,-0x4(%rbp)
jmp    1229 <main+0xd9>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe39(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
mov    $0x1,%edx
call   1070 <pread@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    1222 <main+0xd2>
lea    0xe2a(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1229 <main+0xd9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x4d,%ebx
cmp    $0x3,%edi
jne    11b6 <main+0x66>
mov    0x8(%rsi),%r15
mov    0x10(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1040 <open@plt>
test   %eax,%eax
js     11c3 <main+0x73>
mov    %eax,%ebp
lea    0xe84(%rip),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <printf@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
mov    %r14d,%ecx
call   1070 <pread@plt>
xor    %ebx,%ebx
test   %rax,%rax
js     11d1 <main+0x81>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe36(%rip),%rdi
call   1050 <perror@plt>
jmp    11b6 <main+0x66>
lea    0xe5e(%rip),%rdi
call   1050 <perror@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%ebx
jmp    11b6 <main+0x66>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [22 x i8] c"Failed to open sysctl\00"
@.str.1 = [32 x i8] c"Reading from '%s' at offset %d\0A\00"
@.str.2 = [12 x i8] c"Read failed\00"
@errno = global i32 0
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 i64
%10 = alloca [16 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 77, i32* %3
br label %43
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %7
%22 = load i8*, i8** %6
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %14
%28 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 77, i32* %3
br label %43
29: ; preds = %14
%30 = load i8*, i8** %6
%31 = load i32, i32* %7
%32 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %30, i32 %31)
%33 = load i32, i32* %8
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%35 = load i32, i32* %7
%36 = call i64 @pread(i32 %33, i8* %34, i32 1, i32 %35)
store i64 %36, i64* %9
%37 = load i64, i64* %9
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %29
%40 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* @errno
store i32 %41, i32* %3
br label %43
42: ; preds = %29
store i32 0, i32* %3
br label %43
43: ; preds = %42, %39, %27, %13
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [22 x i8] c"Failed to open sysctl\00"
@.str.1 = [32 x i8] c"Reading from '%s' at offset %d\0A\00"
@.str.2 = [12 x i8] c"Read failed\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %6, label %24
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %8, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %6
%16 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %24
17: ; preds = %6
%18 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32 %11)
%19 = call i64 @pread(i32 %13, i8* %4, i32 1, i32 %11)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @errno
br label %24
24: ; preds = %17, %2, %21, %15
%25 = phi i32 [ 77, %15 ], [ %23, %21 ], [ 77, %2 ], [ 0, %17 ]
ret i32 %25
}