#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*/ value;
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int read(int, int *, size_t);
int work_mode(int fd) {
  int value = 0;
  size_t len = sizeof(value);
  ssize_t n = 0;
  for (;;) {
    n = read(fd, &value, len);
    if (n == -1)
      perror("read");
    printf("%s: %d IRQ's occured\n", "/dev/gpio_irq_driver_simple", value);
  }
  return 0;
}


x86 assembly (clang, -O0):
<work_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x4,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rdx
lea    -0x8(%rbp),%rsi
call   1040 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    117a <work_mode+0x4a>
lea    0xe8b(%rip),%rdi
call   1050 <perror@plt>
mov    -0x8(%rbp),%edx
lea    0xe81(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1030 <printf@plt>
jmp    1151 <work_mode+0x21>

x86 assembly (clang, -O2):
<work_mode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%r14
lea    0xead(%rip),%r15
lea    0xeab(%rip),%r12
lea    0xeba(%rip),%r13
jmp    117f <work_mode+0x4f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0xc(%rsp),%edx
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <printf@plt>
mov    $0x4,%edx
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <read@plt>
cmp    $0xffffffff,%eax
jne    1170 <work_mode+0x40>
mov    %r15,%rdi
call   1050 <perror@plt>
jmp    1170 <work_mode+0x40>

LLVM IR (-O0):
@.str = [5 x i8] c"read\00"
@.str.1 = [22 x i8] c"%s: %d IRQ's occured\0A\00"
@.str.2 = [28 x i8] c"/dev/gpio_irq_driver_simple\00"
define i32 @work_mode(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i64 4, i64* %4
store i32 0, i32* %5
br label %6
6: ; preds = %14, %1
%7 = load i32, i32* %2
%8 = load i64, i64* %4
%9 = call i32 @read(i32 %7, i32* %3, i64 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %6
%15 = load i32, i32* %3
%16 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %6
}

LLVM IR (-O2):
@.str = [5 x i8] c"read\00"
@.str.1 = [22 x i8] c"%s: %d IRQ's occured\0A\00"
@.str.2 = [28 x i8] c"/dev/gpio_irq_driver_simple\00"
define i32 @work_mode(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %4
4: ; preds = %9, %1
%5 = call i32 @read(i32 %0, i32* %2, i64 4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %4
%10 = load i32, i32* %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %4
}