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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ vfork();
int main(void) {
  int fd;
  pid_t pid;
  fd = open("/dev/myChar", O_RDWR);
  if (fd < 0)
    perror("Unable to open the device\n");
  else
    printf("File opened successfully %d\n", fd);
  pid = vfork();
  ioctl(fd, getpid(), pid);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11b2 <main+0x42>
lea    0xe64(%rip),%rdi
call   1080 <perror@plt>
jmp    11c1 <main+0x51>
mov    -0x8(%rbp),%esi
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
call   1090 <vfork@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%esi
mov    -0xc(%rbp),%edx
call   1050 <ioctl@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
lea    0xe7c(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11c9 <main+0x59>
lea    0xe91(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
call   1090 <vfork@plt>
mov    %eax,%ebp
xor    %r14d,%r14d
mov    %r14d,%eax
call   1030 <getpid@plt>
mov    %ebx,%edi
mov    %eax,%esi
mov    %ebp,%edx
call   1050 <ioctl@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe3c(%rip),%rdi
call   1080 <perror@plt>
jmp    119d <main+0x2d>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/myChar\00"
@O_RDWR = global i32 0
@.str.1 = [27 x i8] c"Unable to open the device\0A\00"
@.str.2 = [29 x i8] c"File opened successfully %d\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 ([12 x i8], [12 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 %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %13
10: ; preds = %0
%11 = load i32, i32* %2
%12 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %10, %8
%14 = call i32 @vfork()
store i32 %14, i32* %3
%15 = load i32, i32* %2
%16 = call i32 (...) @getpid()
%17 = load i32, i32* %3
%18 = call i32 @ioctl(i32 %15, i32 %16, i32 %17)
%19 = load i32, i32* %2
%20 = call i32 @close(i32 %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/myChar\00"
@O_RDWR = global i32 0
@.str.1 = [27 x i8] c"Unable to open the device\0A\00"
@.str.2 = [29 x i8] c"File opened successfully %d\0A\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %2)
br label %8
8: ; preds = %6, %4
%9 = call i32 @vfork()
%10 = call i32 (...) @getpid()
%11 = call i32 @ioctl(i32 %2, i32 %10, i32 %9)
%12 = call i32 @close(i32 %2)
ret i32 0
}