#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 O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int msg_send(char *data) {
  int fd = 0;
  fd = open("./msg_leave", O_WRONLY | O_TRUNC);
  if (fd < 0) {
    close(fd);
    return -1;
  }
  close(fd);
  fd = open("./msg_leave", O_WRONLY);
  if (fd < 0) {
    close(fd);
    return -1;
  }
  write(fd, data, strlen(data));
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<msg_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
mov    0x2e95(%rip),%rax
or     (%rax),%esi
lea    0xe94(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1192 <msg_send+0x52>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <msg_send+0xc4>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
lea    0xe56(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d0 <msg_send+0x90>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <msg_send+0xc4>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msg_send>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2e82(%rip),%rbx
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
or     (%rbx),%esi
lea    0xea0(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <close@plt>
test   %ebp,%ebp
js     119e <msg_send+0x5e>
mov    (%rbx),%esi
lea    0xe85(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11a5 <msg_send+0x65>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
xor    %ebx,%ebx
jmp    11aa <msg_send+0x6a>
mov    $0xffffffff,%ebx
jmp    11b1 <msg_send+0x71>
mov    $0xffffffff,%ebx
mov    %ebp,%edi
call   1050 <close@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"./msg_leave\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
define i32 @msg_send(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* %4
%13 = call i32 @close(i32 %12)
store i32 -1, i32* %2
br label %32
14: ; preds = %1
%15 = load i32, i32* %4
%16 = call i32 @close(i32 %15)
%17 = load i32, i32* @O_WRONLY
%18 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i32, i32* %4
%23 = call i32 @close(i32 %22)
store i32 -1, i32* %2
br label %32
24: ; preds = %14
%25 = load i32, i32* %4
%26 = load i8*, i8** %3
%27 = load i8*, i8** %3
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @write(i32 %25, i8* %26, i32 %28)
%30 = load i32, i32* %4
%31 = call i32 @close(i32 %30)
store i32 0, i32* %2
br label %32
32: ; preds = %24, %21, %11
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@.str = [12 x i8] c"./msg_leave\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
define i32 @msg_send(i8* %0) {
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @O_TRUNC
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
%7 = tail call i32 @close(i32 %5)
br i1 %6, label %18, label %8
8: ; preds = %1
%9 = load i32, i32* @O_WRONLY
%10 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = tail call i32 @strlen(i8* %0)
%14 = tail call i32 @write(i32 %10, i8* %0, i32 %13)
br label %15
15: ; preds = %8, %12
%16 = phi i32 [ 0, %12 ], [ -1, %8 ]
%17 = tail call i32 @close(i32 %10)
br label %18
18: ; preds = %15, %1
%19 = phi i32 [ -1, %1 ], [ %16, %15 ]
ret i32 %19
}