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

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int ec_open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ fatal(char *);
int write(int, int /*<<< orphan*/ *, unsigned int);
void ec_write(const char *filename, uint8_t *buffer,
              unsigned int bufferlength) {
  int fd;
  ssize_t len;
  fd = ec_open(filename, O_WRONLY);
  len = write(fd, buffer, bufferlength);
  if (len == -1) {
    fatal("in ec_write() on writing file");
  }
  close(fd);
}


x86 assembly (clang, -O0):
<ec_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
call   1030 <ec_open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1190 <ec_write+0x50>
lea    0xe75(%rip),%rdi
call   1060 <fatal@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ec_write>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbp
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
call   1030 <ec_open@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1178 <ec_write+0x38>
lea    0xe8d(%rip),%rdi
call   1060 <fatal@plt>
mov    %ebx,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <close@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@.str = [30 x i8] c"in ec_write() on writing file\00"
define void @ec_write(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_WRONLY
%11 = call i32 @ec_open(i8* %9, i32 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = load i32*, i32** %5
%14 = load i32, i32* %6
%15 = call i32 @write(i32 %12, i32* %13, i32 %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = call i32 @fatal(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %3
%21 = load i32, i32* %7
%22 = call i32 @close(i32 %21)
ret void
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@.str = [30 x i8] c"in ec_write() on writing file\00"
define void @ec_write(i8* %0, i32* nocapture %1, i32 %2) {
%4 = load i32, i32* @O_WRONLY
%5 = tail call i32 @ec_open(i8* %0, i32 %4)
%6 = tail call i32 @write(i32 %5, i32* %1, i32 %2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @fatal(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %3
%11 = tail call i32 @close(i32 %5)
ret void
}