#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*/ get_data_from_device(int);
int /*<<< orphan*/ get_nth_char_from_device(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ put_data_to_the_device(int, char *);
int main() {
  int devie_ptr, ret_val;
  char *message = "IOCTL message write";
  devie_ptr = open("/dev/char_dev", 0);
  if (devie_ptr < 0) {
    printf("%s %s\n", "Cann't open the file ", "/dev/char_dev");
  }
  get_data_from_device(devie_ptr);
  get_nth_char_from_device(devie_ptr);
  put_data_to_the_device(devie_ptr, message);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xea3(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    119f <main+0x4f>
lea    0xe96(%rip),%rdi
lea    0xe96(%rip),%rsi
lea    0xe7a(%rip),%rdx
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1070 <get_data_from_device@plt>
mov    -0x8(%rbp),%edi
call   1050 <get_nth_char_from_device@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <put_data_to_the_device@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xebc(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    117f <main+0x2f>
lea    0xeb6(%rip),%rdi
lea    0xeb6(%rip),%rsi
lea    0xe9a(%rip),%rdx
call   1030 <printf@plt>
mov    %ebx,%edi
call   1070 <get_data_from_device@plt>
mov    %ebx,%edi
call   1050 <get_nth_char_from_device@plt>
lea    0xe6c(%rip),%rsi
mov    %ebx,%edi
call   1040 <put_data_to_the_device@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"IOCTL message write\00"
@.str.1 = [14 x i8] c"/dev/char_dev\00"
@.str.2 = [7 x i8] c"%s %s\0A\00"
@.str.3 = [22 x i8] c"Cann't open the file \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 0)
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 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = load i32, i32* %2
%12 = call i32 @get_data_from_device(i32 %11)
%13 = load i32, i32* %2
%14 = call i32 @get_nth_char_from_device(i32 %13)
%15 = load i32, i32* %2
%16 = load i8*, i8** %4
%17 = call i32 @put_data_to_the_device(i32 %15, i8* %16)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"IOCTL message write\00"
@.str.1 = [14 x i8] c"/dev/char_dev\00"
@.str.2 = [7 x i8] c"%s %s\0A\00"
@.str.3 = [22 x i8] c"Cann't open the file \00"
define i32 @main() {
%1 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 0)
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = tail call i32 @get_data_from_device(i32 %1)
%7 = tail call i32 @get_nth_char_from_device(i32 %1)
%8 = tail call i32 @put_data_to_the_device(i32 %1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
ret i32 0
}