#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*/ data;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int main(void) {
  int fd;
  int data;
  fd = open("/dev/temp", O_RDWR);
  if (fd < 0) {
    perror("open");
    exit(0);
  }
  while (1) {
    read(fd, (char *)&data, sizeof(data));
    sleep(1);
    printf("%x\n", data);
  }
  close(fd);
  printf("/dev/temp closed :)\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11a4 <main+0x44>
lea    0xe72(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jmp    11a9 <main+0x49>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    -0xc(%rbp),%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a9 <main+0x49>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     11b9 <main+0x59>
mov    %eax,%ebx
lea    0xc(%rsp),%r14
lea    0xe7f(%rip),%r15
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    0xc(%rsp),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1190 <main+0x30>
lea    0xe4a(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/temp\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [4 x i8] c"%x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %0
br label %12
12: ; preds = %11, %12
%13 = load i32, i32* %2
%14 = bitcast i32* %3 to i8*
%15 = call i32 @read(i32 %13, i8* %14, i32 4)
%16 = call i32 @sleep(i32 1)
%17 = load i32, i32* %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %12
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/temp\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [4 x i8] c"%x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %0, %9
%10 = call i32 @read(i32 %4, i8* %2, i32 4)
%11 = tail call i32 @sleep(i32 1)
%12 = load i32, i32* %1
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %9
}