#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 */
typedef int /*<<< orphan*/ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  char *msg = "Test";
  int size = strlen(msg);
  int file_handle = open("/dev/trans0", O_RDWR);
  ssize_t result = write(file_handle, msg, size);
  char *enc_msg = malloc(sizeof(char) * size);
  read(file_handle, enc_msg, size);
  printf("%s -> %s\n", msg, enc_msg);
  close(file_handle);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    0xe5f(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1070 <read@plt>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe20(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe82(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe6d(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%r15d
mov    %eax,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %r15d,%edi
mov    %rax,%rsi
mov    %ebp,%edx
call   1070 <read@plt>
lea    0xe47(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <printf@plt>
mov    %r15d,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"Test\00"
@.str.1 = [12 x i8] c"/dev/trans0\00"
@O_RDWR = global i32 0
@.str.2 = [10 x i8] c"%s -> %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %3
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = load i8*, i8** %2
%13 = load i32, i32* %3
%14 = call i32 @write(i32 %11, i8* %12, i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = mul i64 1, %16
%18 = trunc i64 %17 to i32
%19 = call i8* @malloc(i32 %18)
store i8* %19, i8** %6
%20 = load i32, i32* %4
%21 = load i8*, i8** %6
%22 = load i32, i32* %3
%23 = call i32 @read(i32 %20, i8* %21, i32 %22)
%24 = load i8*, i8** %2
%25 = load i8*, i8** %6
%26 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8* %25)
%27 = load i32, i32* %4
%28 = call i32 @close(i32 %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"Test\00"
@.str.1 = [12 x i8] c"/dev/trans0\00"
@O_RDWR = global i32 0
@.str.2 = [10 x i8] c"%s -> %s\0A\00"
define i32 @main() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%4 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %1)
%5 = tail call i8* @malloc(i32 %1)
%6 = tail call i32 @read(i32 %3, i8* %5, i32 %1)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %5)
%8 = tail call i32 @close(i32 %3)
ret i32 0
}