#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*/ fscanf(int /*<<< orphan*/, char *, unsigned 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*/ stdin;
int main(void) {
  int fd;
  unsigned int a;
  fd = open("/dev/myChar2", 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());
  fscanf(stdin, "%d", &a);
  getchar();
  ioctl(fd, getpid(), a);
  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>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <fscanf@plt>
mov    $0x0,%al
call   1080 <getchar@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   1060 <ioctl@plt>
mov    -0x8(%rbp),%edi
call   1070 <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     1207 <main+0x87>
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>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1050 <fscanf@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    0xc(%rsp),%edx
mov    %ebx,%edi
mov    %eax,%esi
call   1060 <ioctl@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xdff(%rip),%rdi
call   10a0 <perror@plt>
jmp    11ae <main+0x2e>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/myChar2\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"
@stdin = global i32 0
@.str.4 = [3 x i8] c"%d\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 = load i32, i32* @stdin
%17 = call i32 @fscanf(i32 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%18 = call i32 (...) @getchar()
%19 = load i32, i32* %2
%20 = call i32 (...) @getpid()
%21 = load i32, i32* %3
%22 = call i32 @ioctl(i32 %19, i32 %20, i32 %21)
%23 = load i32, i32* %2
%24 = call i32 @close(i32 %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/myChar2\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"
@stdin = global i32 0
@.str.4 = [3 x i8] c"%d\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 = load i32, i32* @stdin
%14 = call i32 @fscanf(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%15 = call i32 (...) @getchar()
%16 = call i32 (...) @getpid()
%17 = load i32, i32* %1
%18 = call i32 @ioctl(i32 %4, i32 %16, i32 %17)
%19 = call i32 @close(i32 %4)
ret i32 0
}