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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char **, int);
main() {
  int fd;
  char num[2];
  fd = open("/dev/fgj", O_RDWR, S_IRUSR | S_IWUSR);
  if (fd != -1) {
    while (1) {
      read(fd, &num, 2);
      printf("The data is %s\n", num);
      if (num[1] == 0x35) {
        close(fd);
        break;
      }
    }
  } else {
    printf("device open failure\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
mov    0x2e78(%rip),%rax
or     (%rax),%edx
lea    0xe8f(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     11cf <main+0x8f>
jmp    1188 <main+0x48>
mov    -0x8(%rbp),%edi
lea    -0xa(%rbp),%rsi
mov    $0x2,%edx
call   1050 <read@plt>
lea    -0xa(%rbp),%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x9(%rbp),%eax
cmp    $0x35,%eax
jne    11c5 <main+0x85>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
jmp    11ca <main+0x8a>
jmp    1188 <main+0x48>
jmp    11dd <main+0x9d>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    0x2e68(%rip),%rax
mov    0x2e71(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe86(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11cc <main+0x7c>
mov    %eax,%ebp
lea    0xe(%rsp),%rbx
lea    0xe77(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1060 <read@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmpb   $0x35,0xf(%rsp)
jne    11a0 <main+0x50>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11d8 <main+0x88>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/fgj\00"
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [16 x i8] c"The data is %s\0A\00"
@.str.2 = [21 x i8] c"device open failure\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i8]
store i32 0, i32* %1
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @S_IRUSR
%6 = load i32, i32* @S_IWUSR
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %27
11: ; preds = %0
br label %12
12: ; preds = %11, %25
%13 = load i32, i32* %2
%14 = bitcast [2 x i8]* %3 to i8**
%15 = call i32 @read(i32 %13, i8** %14, i32 2)
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 53
br i1 %21, label %22, label %25
22: ; preds = %12
%23 = load i32, i32* %2
%24 = call i32 @close(i32 %23)
br label %26
25: ; preds = %12
br label %12
26: ; preds = %22
br label %29
27: ; preds = %0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %26
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/fgj\00"
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [16 x i8] c"The data is %s\0A\00"
@str = [20 x i8] c"device open failure\00"
define i32 @main() {
%1 = alloca [2 x i8]
%2 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @S_IRUSR
%5 = load i32, i32* @S_IWUSR
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %19, label %9
9: ; preds = %0
%10 = bitcast [2 x i8]* %1 to i8**
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 1
br label %12
12: ; preds = %9, %12
%13 = call i32 @read(i32 %7, i8** %10, i32 2)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%15 = load i8, i8* %11
%16 = icmp eq i8 %15, 53
br i1 %16, label %17, label %12
17: ; preds = %12
%18 = call i32 @close(i32 %7)
br label %21
19: ; preds = %0
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %19, %17
ret i32 0
}