#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*/ abort();
int errno;
int /*<<< orphan*/ printf(char *, int);
scalar_t__ write(int, void *, size_t);
void insert_raw_model(int fd, void *data, size_t len) {
  if (fd < 0) {
    printf("Error opening file: %d\n", errno);
    abort();
  }
  if (write(fd, data, len) <= 0) {
    printf("Error %d writing on file\n", errno);
    abort();
  }
}


x86 assembly (clang, -O0):
<insert_raw_model>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1169 <insert_raw_model+0x39>
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xea3(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <write@plt>
cmp    $0x0,%rax
jg     119f <insert_raw_model+0x6f>
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert_raw_model>:
push   %rax
test   %edi,%edi
js     1141 <insert_raw_model+0x11>
call   1040 <write@plt>
test   %rax,%rax
jle    1153 <insert_raw_model+0x23>
pop    %rax
ret
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
lea    0xeaf(%rip),%rdi
jmp    1163 <insert_raw_model+0x33>
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    0xeb5(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Error opening file: %d\0A\00"
@errno = global i32 0
@.str.1 = [26 x i8] c"Error %d writing on file\0A\00"
define void @insert_raw_model(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = load i32, i32* @errno
%11 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 (...) @abort()
unreachable
13: ; preds = %3
%14 = load i32, i32* %4
%15 = load i8*, i8** %5
%16 = load i64, i64* %6
%17 = call i64 @write(i32 %14, i8* %15, i64 %16)
%18 = icmp sle i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load i32, i32* @errno
%21 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"Error opening file: %d\0A\00"
@errno = global i32 0
@.str.1 = [26 x i8] c"Error %d writing on file\0A\00"
define void @insert_raw_model(i32 %0, i8* nocapture %1, i64 %2) {
%4 = icmp slt i32 %0, 0
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = load i32, i32* @errno
%7 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 (...) @abort()
unreachable
9: ; preds = %3
%10 = tail call i64 @write(i32 %0, i8* %1, i64 %2)
%11 = icmp slt i64 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* @errno
%14 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = tail call i32 (...) @abort()
unreachable
16: ; preds = %9
ret void
}