#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 off_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int main(int argc, char *argv[]) {
  int fd = 0, ret = 0;
  off_t offset = 32;
  char buf[32] = {0};
  fd = open("/dev/pgwlk0", O_RDWR);
  if (fd < 0) {
    perror("Opening /dev/pgwalk");
    return -1;
  }
  ret = read(fd, buf, 32);
  if (ret < 0) {
    perror("Read error");
  }
  close(fd);
  while (1)
    ;
  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)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x20,-0x1c(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
lea    0xe65(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c4 <main+0x74>
lea    0xe58(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%eax
add    $0x40,%rsp
pop    %rbp
ret
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11ee <main+0x9e>
lea    0xe37(%rip),%rdi
call   1070 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    11f6 <main+0xa6>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     1192 <main+0x52>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x20,%edx
call   1040 <read@plt>
test   %eax,%eax
js     11a9 <main+0x69>
mov    %ebx,%edi
call   1030 <close@plt>
cs nopw 0x0(%rax,%rax,1)
jmp    1190 <main+0x50>
lea    0xe73(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe70(%rip),%rdi
call   1060 <perror@plt>
jmp    117f <main+0x3f>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/pgwlk0\00"
@O_RDWR = global i32 0
@.str.1 = [20 x i8] c"Opening /dev/pgwalk\00"
@.str.2 = [11 x i8] c"Read error\00"
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 [32 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 32, i32* %8
%10 = bitcast [32 x i8]* %9 to i8*
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
ret i32 -1
17: ; preds = %2
%18 = load i32, i32* %6
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 32)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %17
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
br label %28
28: ; preds = %25, %28
br label %28
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/pgwlk0\00"
@O_RDWR = global i32 0
@.str.1 = [20 x i8] c"Opening /dev/pgwalk\00"
@.str.2 = [11 x i8] c"Read error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
ret i32 -1
10: ; preds = %2
%11 = call i32 @read(i32 %6, i8* %4, i32 32)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = tail call i32 @close(i32 %6)
br label %17
17: ; preds = %17, %15
br label %17
}