#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*/ _IO(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ init_deamon();
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int main(int argc, char **argv) {
  int fd = 0;
  init_deamon();
  fd = open("/dev/merge_mem", O_RDWR);
  if (fd == -1) {
    perror("open");
    printf("err open dev\r\n");
  }
  ioctl(fd, _IO(0xF6, 1), NULL);
  close(fd);
  while (1) {
    sleep(1);
  }
  exit(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1090 <init_deamon@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
lea    0xe4c(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11de <main+0x5e>
lea    0xe42(%rip),%rdi
call   1080 <perror@plt>
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0xf6,%edi
mov    $0x1,%esi
call   1040 <_IO@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <ioctl@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
jmp    1209 <main+0x89>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1090 <init_deamon@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11dc <main+0x5c>
mov    $0xf6,%edi
mov    $0x1,%esi
call   1040 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
mov    %ebx,%edi
call   1060 <close@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%edi
call   10a0 <sleep@plt>
jmp    11d0 <main+0x50>
lea    0xe2c(%rip),%rdi
call   1080 <perror@plt>
lea    0xe25(%rip),%rdi
call   1030 <puts@plt>
jmp    11a4 <main+0x24>

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/merge_mem\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [15 x i8] c"err open dev\0D\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%7 = call i32 (...) @init_deamon()
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %12, %2
%16 = load i32, i32* %6
%17 = call i32 @_IO(i32 246, i32 1)
%18 = call i32 @ioctl(i32 %16, i32 %17, i32* null)
%19 = load i32, i32* %6
%20 = call i32 @close(i32 %19)
br label %21
21: ; preds = %15, %21
%22 = call i32 @sleep(i32 1)
br label %21
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/merge_mem\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@str = [14 x i8] c"err open dev\0D\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @init_deamon()
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %7, %2
%11 = tail call i32 @_IO(i32 246, i32 1)
%12 = tail call i32 @ioctl(i32 %5, i32 %11, i32* null)
%13 = tail call i32 @close(i32 %5)
br label %14
14: ; preds = %14, %10
%15 = tail call i32 @sleep(i32 1)
br label %14
}