#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_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ ioctl_get_msg(int);
int /*<<< orphan*/ ioctl_get_nth_byte(int);
int /*<<< orphan*/ ioctl_set_msg(int, char *);
scalar_t__ malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
main() {
  int file_desc, ret;
  char *msg = (char *)malloc(7943);
  int size = 7943;
  int fd = open("bar3.so", O_RDONLY);
  ret = read(fd, msg, 7943);
  if (ret < 0) {
    perror("read");
  }
  file_desc = open("test_driver2_dev", 0);
  if (file_desc < 0) {
    printf("Can't open device file: %s\n", "test_driver2_dev");
    exit(-1);
  }
  ioctl_get_nth_byte(file_desc);
  ioctl_get_msg(file_desc);
  ioctl_set_msg(file_desc, msg);
  close(file_desc);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1f07,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1f07,-0x1c(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
lea    0xe2c(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x1f07,%edx
call   1060 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1206 <main+0x66>
lea    0xe07(%rip),%rdi
call   10b0 <perror@plt>
lea    0xe00(%rip),%rdi
xor    %esi,%esi
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    123e <main+0x9e>
lea    0xdf6(%rip),%rdi
lea    0xdde(%rip),%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%edi
call   1030 <ioctl_get_nth_byte@plt>
mov    -0x8(%rbp),%edi
call   1090 <ioctl_get_msg@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1070 <ioctl_set_msg@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1f07,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
lea    0xe40(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x1f07,%edx
call   1060 <read@plt>
test   %eax,%eax
js     1214 <main+0x74>
lea    0xe2e(%rip),%rdi
xor    %esi,%esi
call   10a0 <open@plt>
test   %eax,%eax
js     1222 <main+0x82>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <ioctl_get_nth_byte@plt>
mov    %ebp,%edi
call   1090 <ioctl_get_msg@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <ioctl_set_msg@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xded(%rip),%rdi
call   10b0 <perror@plt>
jmp    11d8 <main+0x38>
lea    0xdf5(%rip),%rdi
lea    0xddd(%rip),%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"bar3.so\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"read\00"
@.str.2 = [17 x i8] c"test_driver2_dev\00"
@.str.3 = [28 x i8] c"Can't open device file: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i64 @malloc(i32 7943)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %4
store i32 7943, i32* %5
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = load i8*, i8** %4
%13 = call i32 @read(i32 %11, i8* %12, i32 7943)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %0
%19 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 0)
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %18
%26 = load i32, i32* %2
%27 = call i32 @ioctl_get_nth_byte(i32 %26)
%28 = load i32, i32* %2
%29 = call i32 @ioctl_get_msg(i32 %28)
%30 = load i32, i32* %2
%31 = load i8*, i8** %4
%32 = call i32 @ioctl_set_msg(i32 %30, i8* %31)
%33 = load i32, i32* %2
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [8 x i8] c"bar3.so\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"read\00"
@.str.2 = [17 x i8] c"test_driver2_dev\00"
@.str.3 = [28 x i8] c"Can't open device file: %s\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 7943)
%2 = inttoptr i64 %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @read(i32 %4, i8* %2, i32 7943)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = tail call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 0)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %9
%16 = tail call i32 @ioctl_get_nth_byte(i32 %10)
%17 = tail call i32 @ioctl_get_msg(i32 %10)
%18 = tail call i32 @ioctl_set_msg(i32 %10, i8* %2)
%19 = tail call i32 @close(i32 %10)
ret i32 0
}