#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*/ assert(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  assert(argc > 1);
  char buf[100];
  char i = 0;
  memset(buf, 0, 100);
  printf("Input: %s\n", argv[1]);
  int fp = open("/dev/myDev", O_RDWR);
  write(fp, argv[1], strlen(argv[1]));
  while (read(fp, &buf[i++], 1))
    ;
  printf("Reversed by the driver: %s\n", buf);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
movb   $0x0,-0x81(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe40(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
lea    0xe36(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x88(%rbp)
mov    -0x88(%rbp),%eax
mov    %eax,-0x94(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x90(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x94(%rbp),%edi
mov    -0x90(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x88(%rbp),%edi
mov    -0x81(%rbp),%al
mov    %al,%cl
add    $0x1,%cl
mov    %cl,-0x81(%rbp)
movsbq %al,%rax
lea    -0x80(%rbp),%rsi
add    %rax,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0x0,%rax
je     1257 <main+0xe7>
jmp    121c <main+0xac>
lea    -0x80(%rbp),%rsi
lea    0xdb4(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %rsi,%r14
xor    %eax,%eax
cmp    $0x2,%edi
setge  %al
mov    %eax,%edi
call   1080 <assert@plt>
mov    %rsp,%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
mov    0x8(%r14),%rsi
lea    0xe5a(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
lea    0xe50(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
mov    0x8(%r14),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
nopw   0x0(%rax,%rax,1)
movsbq %bl,%rax
add    $0x1,%bl
lea    (%rsp,%rax,1),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1070 <read@plt>
test   %rax,%rax
jne    11e0 <main+0x70>
lea    0xe13(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Input: %s\0A\00"
@.str.1 = [11 x i8] c"/dev/myDev\00"
@O_RDWR = global i32 0
@.str.2 = [28 x i8] c"Reversed by the driver: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i8
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
store i8 0, i8* %7
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 100)
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @O_RDWR
%20 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @write(i32 %21, i8* %24, i32 %28)
br label %30
30: ; preds = %38, %2
%31 = load i32, i32* %8
%32 = load i8, i8* %7
%33 = add i8 %32, 1
store i8 %33, i8* %7
%34 = sext i8 %32 to i64
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %34
%36 = call i64 @read(i32 %31, i8* %35, i32 1)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %30
br label %30
39: ; preds = %30
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%41 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [11 x i8] c"Input: %s\0A\00"
@.str.1 = [11 x i8] c"/dev/myDev\00"
@O_RDWR = global i32 0
@.str.2 = [28 x i8] c"Reversed by the driver: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = icmp sgt i32 %0, 1
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 100)
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = load i8*, i8** %9
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @write(i32 %13, i8* %14, i32 %15)
br label %17
17: ; preds = %17, %2
%18 = phi i8 [ 0, %2 ], [ %19, %17 ]
%19 = add i8 %18, 1
%20 = sext i8 %18 to i64
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %20
%22 = call i64 @read(i32 %13, i8* %21, i32 1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %17
24: ; preds = %17
%25 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %7)
ret i32 0
}