#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 open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int msgr(char *dev) {
  printf("start %s\n", dev);
  int fd = open(dev, O_RDWR);
  if (fd < 0) {
    printf("%s - err open\n", dev);
    return -1;
  }
  char data[100];
  int ret;
  ret = read(fd, data, 100);
  if (ret < 0) {
    printf("%s - err read\n", dev);
    return -1;
  }
  data[ret] = '\0';
  printf("letto: %s\n", data);
  close(fd);
}


x86 assembly (clang, -O0):
<msgr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    119a <msgr+0x5a>
mov    -0x10(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <msgr+0xbe>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1050 <read@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jge    11da <msgr+0x9a>
mov    -0x10(%rbp),%rsi
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <msgr+0xbe>
movslq -0x84(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msgr>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%rbx
lea    0xeb0(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11a0 <msgr+0x60>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x64,%edx
call   1050 <read@plt>
test   %eax,%eax
js     11a9 <msgr+0x69>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xe99(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
mov    %ebp,%edi
call   1040 <close@plt>
jmp    11b8 <msgr+0x78>
lea    0xe63(%rip),%rdi
jmp    11b0 <msgr+0x70>
lea    0xe69(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"start %s\0A\00"
@O_RDWR = global i32 0
@.str.1 = [15 x i8] c"%s - err open\0A\00"
@.str.2 = [15 x i8] c"%s - err read\0A\00"
@.str.3 = [11 x i8] c"letto: %s\0A\00"
define i32 @msgr(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i8*, i8** %3
%10 = load i32, i32* @O_RDWR
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 -1, i32* %2
br label %34
17: ; preds = %1
%18 = load i32, i32* %4
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 100)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i8*, i8** %3
%25 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %24)
store i32 -1, i32* %2
br label %34
26: ; preds = %17
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %28
store i8 0, i8* %29
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%31 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = load i32, i32* %4
%33 = call i32 @close(i32 %32)
br label %34
34: ; preds = %26, %23, %14
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [10 x i8] c"start %s\0A\00"
@O_RDWR = global i32 0
@.str.1 = [15 x i8] c"%s - err open\0A\00"
@.str.2 = [15 x i8] c"%s - err read\0A\00"
@.str.3 = [11 x i8] c"letto: %s\0A\00"
define i32 @msgr(i8* %0) {
%2 = alloca [100 x i8]
%3 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %21
9: ; preds = %1
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%11 = call i32 @read(i32 %5, i8* %10, i32 100)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %20
15: ; preds = %9
%16 = zext i32 %11 to i64
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %16
store i8 0, i8* %17
%18 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%19 = call i32 @close(i32 %5)
br label %20
20: ; preds = %15, %13
br label %21
21: ; preds = %20, %7
ret i32 -1
}