#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 /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void Hi_IR_FUNC_TEST_002() {
  int fp, fp2;
  printf("Hi_IR_FUNC_TEST_002 start...\n");
  printf("REMOTE codetype ...NEC with simple repeat code - uPD6121G\n");
  if (-1 == (fp = open("/dev/"
                       "Hi_IR",
                       O_RDWR))) {
    printf("Hi_IR_FUNC_TEST_002 ERROR:can not open %s device. read return %d\n",
           "Hi_IR", fp);
    return;
  }
  if (-1 != (fp2 = open("/dev/"
                        "Hi_IR",
                        O_RDWR))) {
    printf("Hi_IR_FUNC_TEST_002 ERROR:can not open %s device. read return %d\n",
           "Hi_IR", fp2);
    return;
  }
  close(fp2);
  close(fp2);
  close(fp2);
  close(fp);
  if (-1 == (fp = open("/dev/"
                       "Hi_IR",
                       O_RDWR))) {
    printf("Hi_IR_FUNC_TEST_002 ERROR:can not open %s device. read return %d\n",
           "Hi_IR", fp);
    return;
  }
  close(fp);
  printf("Hi_IR_FUNC_TEST_002 pass.\n\n");
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
lea    0xef5(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x4(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1198 <Hi_IR_FUNC_TEST_002+0x68>
mov    -0x4(%rbp),%edx
lea    0xedf(%rip),%rdi
lea    0xed2(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1256 <Hi_IR_FUNC_TEST_002+0x126>
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     11dc <Hi_IR_FUNC_TEST_002+0xac>
mov    -0x8(%rbp),%edx
lea    0xe9b(%rip),%rdi
lea    0xe8e(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1256 <Hi_IR_FUNC_TEST_002+0x126>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
lea    0xe4d(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x4(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1240 <Hi_IR_FUNC_TEST_002+0x110>
mov    -0x4(%rbp),%edx
lea    0xe37(%rip),%rdi
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1256 <Hi_IR_FUNC_TEST_002+0x126>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %r14
push   %rbx
push   %rax
lea    0xf02(%rip),%rdi
call   1030 <puts@plt>
lea    0xf13(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e85(%rip),%r14
mov    (%r14),%esi
lea    0xe93(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11f2 <Hi_IR_FUNC_TEST_002+0xb2>
mov    %eax,%ebx
mov    (%r14),%esi
lea    0xe7d(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     119f <Hi_IR_FUNC_TEST_002+0x5f>
lea    0xe77(%rip),%rdi
lea    0xe6a(%rip),%rsi
mov    %eax,%edx
jmp    1205 <Hi_IR_FUNC_TEST_002+0xc5>
mov    $0xffffffff,%edi
call   1050 <close@plt>
mov    $0xffffffff,%edi
call   1050 <close@plt>
mov    $0xffffffff,%edi
call   1050 <close@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    (%r14),%esi
lea    0xe32(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11f2 <Hi_IR_FUNC_TEST_002+0xb2>
mov    %eax,%edi
call   1050 <close@plt>
lea    0xebe(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>
lea    0xe12(%rip),%rdi
lea    0xe05(%rip),%rsi
mov    $0xffffffff,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Hi_IR_FUNC_TEST_002 start...\0A\00"
@.str.1 = [59 x i8] c"REMOTE codetype ...NEC with simple repeat code - uPD6121G\0A\00"
@.str.2 = [11 x i8] c"/dev/Hi_IR\00"
@O_RDWR = global i32 0
@.str.3 = [66 x i8] c"Hi_IR_FUNC_TEST_002 ERROR:can not open %s device. read return %d\0A\00"
@.str.4 = [6 x i8] c"Hi_IR\00"
@.str.5 = [28 x i8] c"Hi_IR_FUNC_TEST_002 pass.\0A\0A\00"
define void @Hi_IR_FUNC_TEST_002() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%5 = load i32, i32* @O_RDWR
%6 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %5)
store i32 %6, i32* %1
%7 = icmp eq i32 -1, %6
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %9)
br label %37
11: ; preds = %0
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %12)
store i32 %13, i32* %2
%14 = icmp ne i32 -1, %13
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %16)
br label %37
18: ; preds = %11
%19 = load i32, i32* %2
%20 = call i32 @close(i32 %19)
%21 = load i32, i32* %2
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* %2
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %1
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* @O_RDWR
%28 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %27)
store i32 %28, i32* %1
%29 = icmp eq i32 -1, %28
br i1 %29, label %30, label %33
30: ; preds = %18
%31 = load i32, i32* %1
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %31)
br label %37
33: ; preds = %18
%34 = load i32, i32* %1
%35 = call i32 @close(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %33, %30, %15, %8
ret void
}

LLVM IR (-O2):
@.str.2 = [11 x i8] c"/dev/Hi_IR\00"
@O_RDWR = global i32 0
@.str.3 = [66 x i8] c"Hi_IR_FUNC_TEST_002 ERROR:can not open %s device. read return %d\0A\00"
@.str.4 = [6 x i8] c"Hi_IR\00"
@str = [29 x i8] c"Hi_IR_FUNC_TEST_002 start...\00"
@str.6 = [58 x i8] c"REMOTE codetype ...NEC with simple repeat code - uPD6121G\00"
@str.7 = [27 x i8] c"Hi_IR_FUNC_TEST_002 pass.\0A\00"
define void @Hi_IR_FUNC_TEST_002() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.6, i64 0, i64 0))
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 -1)
br label %27
8: ; preds = %0
%9 = load i32, i32* @O_RDWR
%10 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %10)
br label %27
14: ; preds = %8
%15 = tail call i32 @close(i32 -1)
%16 = tail call i32 @close(i32 -1)
%17 = tail call i32 @close(i32 -1)
%18 = tail call i32 @close(i32 %4)
%19 = load i32, i32* @O_RDWR
%20 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 -1)
br label %27
24: ; preds = %14
%25 = tail call i32 @close(i32 %20)
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.7, i64 0, i64 0))
br label %27
27: ; preds = %24, %22, %12, %6
ret void
}