#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 /*<<< orphan*/ getchar();
int getpid();
int /*<<< orphan*/ ioctl(int, int, unsigned int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, unsigned int *);
int main(void) {
  int fd;
  unsigned int a;
  fd = open("/dev/myChar1", O_RDWR);
  if (fd < 0)
    perror("Unable to open the device\n");
  else
    printf("File opened successfully %d\n", fd);
  printf("PID in device file --> %d\n", getpid());
  scanf("%x", &a);
  ioctl(fd, getpid(), a);
  getchar();
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11c2 <main+0x42>
lea    0xe55(%rip),%rdi
call   10a0 <perror@plt>
jmp    11d1 <main+0x51>
mov    -0x8(%rbp),%esi
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe64(%rip),%rdi
call   1040 <printf@plt>
lea    0xe73(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1080 <scanf@plt>
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    $0x0,%al
call   1070 <getchar@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
lea    0xe6b(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11fe <main+0x7e>
lea    0xe81(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe89(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0xe96(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    0xc(%rsp),%edx
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe08(%rip),%rdi
call   10a0 <perror@plt>
jmp    11ae <main+0x2e>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/myChar1\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"
@.str.3 = [27 x i8] c"PID in device file --> %d\0A\00"
@.str.4 = [3 x i8] c"%x\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 ([13 x i8], [13 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 (...) @getpid()
%15 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%17 = load i32, i32* %2
%18 = call i32 (...) @getpid()
%19 = load i32, i32* %3
%20 = call i32 @ioctl(i32 %17, i32 %18, i32 %19)
%21 = call i32 (...) @getchar()
%22 = load i32, i32* %2
%23 = call i32 @close(i32 %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/myChar1\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"
@.str.3 = [27 x i8] c"PID in device file --> %d\0A\00"
@.str.4 = [3 x i8] c"%x\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %10
8: ; preds = %0
%9 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %4)
br label %10
10: ; preds = %8, %6
%11 = tail call i32 (...) @getpid()
%12 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%14 = call i32 (...) @getpid()
%15 = load i32, i32* %1
%16 = call i32 @ioctl(i32 %4, i32 %14, i32 %15)
%17 = call i32 (...) @getchar()
%18 = call i32 @close(i32 %4)
ret i32 0
}