#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*/ ioctl(int, char *, int, int);
scalar_t__ malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
int main() {
  char *buf;
  int n;
  buf = (char *)malloc(20);
  strcpy(buf, "ahoj tu pisu");
  int fd = open("/dev/mpp", O_RDWR);
  write(fd, buf, strlen(buf) + 1);
  read(fd, buf, strlen(buf) + 1);
  printf("%s\n", buf);
  ioctl(fd, buf, 100, 2);
  printf("%s\n", buf);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x14,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
lea    0xe40(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1090 <read@plt>
mov    -0x10(%rbp),%rsi
lea    0xde2(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x64,%edx
mov    $0x2,%ecx
call   1070 <ioctl@plt>
mov    -0x10(%rbp),%rsi
lea    0xdbc(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x14,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
lea    0xe58(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
lea    0xe4d(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <write@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <read@plt>
lea    0xe1c(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
mov    $0x2,%ecx
call   1070 <ioctl@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"ahoj tu pisu\00"
@.str.1 = [9 x i8] c"/dev/mpp\00"
@O_RDWR = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i64 @malloc(i32 20)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 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 i8*, i8** %2
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %14, 1
%16 = call i32 @write(i32 %11, i8* %12, i64 %15)
%17 = load i32, i32* %4
%18 = load i8*, i8** %2
%19 = load i8*, i8** %2
%20 = call i64 @strlen(i8* %19)
%21 = add nsw i64 %20, 1
%22 = call i32 @read(i32 %17, i8* %18, i64 %21)
%23 = load i8*, i8** %2
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %4
%26 = load i8*, i8** %2
%27 = call i32 @ioctl(i32 %25, i8* %26, i32 100, i32 2)
%28 = load i8*, i8** %2
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = load i32, i32* %4
%31 = call i32 @close(i32 %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"ahoj tu pisu\00"
@.str.1 = [9 x i8] c"/dev/mpp\00"
@O_RDWR = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 20)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%7 = add nsw i64 %6, 1
%8 = tail call i32 @write(i32 %5, i8* %2, i64 %7)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%10 = add nsw i64 %9, 1
%11 = tail call i32 @read(i32 %5, i8* %2, i64 %10)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%13 = tail call i32 @ioctl(i32 %5, i8* %2, i32 100, i32 2)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%15 = tail call i32 @close(i32 %5)
ret i32 0
}