#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 *);
scalar_t__ strlen(char *);
int write(int, char *, int);
int msgw(char *dev, char *s) {
  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;
  int l = (int)strlen(s);
  ret = write(fd, s, l);
  if (ret < 0) {
    printf("%s - err write\n", dev);
    return -1;
  }
  close(fd);
}


x86 assembly (clang, -O0):
<msgw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe92(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11ae <msgw+0x5e>
mov    -0x10(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1206 <msgw+0xb6>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x88(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x88(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jge    11fe <msgw+0xae>
mov    -0x10(%rbp),%rsi
lea    0xe2c(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1206 <msgw+0xb6>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msgw>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe9f(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11a1 <msgw+0x51>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %eax,%eax
js     11aa <msgw+0x5a>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    11b9 <msgw+0x69>
lea    0xe62(%rip),%rdi
jmp    11b1 <msgw+0x61>
lea    0xe68(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
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 = [16 x i8] c"%s - err write\0A\00"
define i32 @msgw(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [100 x i8]
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %4
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %18)
store i32 -1, i32* %3
br label %36
20: ; preds = %2
%21 = load i8*, i8** %5
%22 = call i64 @strlen(i8* %21)
%23 = trunc i64 %22 to i32
store i32 %23, i32* %9
%24 = load i32, i32* %6
%25 = load i8*, i8** %5
%26 = load i32, i32* %9
%27 = call i32 @write(i32 %24, i8* %25, i32 %26)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %20
%31 = load i8*, i8** %4
%32 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %31)
store i32 -1, i32* %3
br label %36
33: ; preds = %20
%34 = load i32, i32* %6
%35 = call i32 @close(i32 %34)
br label %36
36: ; preds = %33, %30, %17
%37 = load i32, i32* %3
ret i32 %37
}

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 = [16 x i8] c"%s - err write\0A\00"
define i32 @msgw(i8* %0, i8* nocapture %1) {
%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 = %2
%8 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %18
9: ; preds = %2
%10 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%11 = trunc i64 %10 to i32
%12 = tail call i32 @write(i32 %5, i8* %1, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %18
16: ; preds = %9
%17 = tail call i32 @close(i32 %5)
br label %18
18: ; preds = %14, %16, %7
ret i32 -1
}