#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 scalar_t__ ssize_t;

/* Variables and functions */
scalar_t__ EPIPE;
int /*<<< orphan*/ die();
scalar_t__ errno;
int /*<<< orphan*/ panic(char *);
scalar_t__ write(int, void const *, size_t);
ssize_t write_or_die(int fd, const void *buf, size_t len) {
  ssize_t ret = write(fd, buf, len);
  if (ret < 0) {
    if (errno == EPIPE)
      die();
    panic("Cannot write to descriptor!");
  }
  return ret;
}


x86 assembly (clang, -O0):
<write_or_die>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    118f <write_or_die+0x5f>
mov    0x2e6f(%rip),%rax
mov    (%rax),%rax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%rax
jne    1183 <write_or_die+0x53>
mov    $0x0,%al
call   1050 <die@plt>
lea    0xe76(%rip),%rdi
call   1040 <panic@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_or_die>:
push   %rbx
call   1030 <write@plt>
mov    %rax,%rbx
test   %rax,%rax
jns    1167 <write_or_die+0x37>
mov    0x2e93(%rip),%rax
mov    (%rax),%rax
mov    0x2e91(%rip),%rcx
cmp    (%rcx),%rax
jne    115b <write_or_die+0x2b>
xor    %eax,%eax
call   1050 <die@plt>
lea    0xe9e(%rip),%rdi
call   1040 <panic@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i64 0
@EPIPE = global i64 0
@.str = [28 x i8] c"Cannot write to descriptor!\00"
define i64 @write_or_die(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i32, i32* %4
%9 = load i8*, i8** %5
%10 = load i64, i64* %6
%11 = call i64 @write(i32 %8, i8* %9, i64 %10)
store i64 %11, i64* %7
%12 = load i64, i64* %7
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %3
%15 = load i64, i64* @errno
%16 = load i64, i64* @EPIPE
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 (...) @die()
br label %20
20: ; preds = %18, %14
%21 = call i32 @panic(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %3
%23 = load i64, i64* %7
ret i64 %23
}

LLVM IR (-O2):
@errno = global i64 0
@EPIPE = global i64 0
@.str = [28 x i8] c"Cannot write to descriptor!\00"
define i64 @write_or_die(i32 %0, i8* nocapture %1, i64 %2) {
%4 = tail call i64 @write(i32 %0, i8* %1, i64 %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %3
%7 = load i64, i64* @errno
%8 = load i64, i64* @EPIPE
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 (...) @die()
br label %12
12: ; preds = %10, %6
%13 = tail call i32 @panic(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %3
ret i64 %4
}