#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*/ syserror(char *, char *, int);
int write(int, char const *, int);
int vl_copy(int dev, const char *framebuffer, int width, int height,
            char *error_text, int text_len) {
  int size = width * height * 4;
  if (write(dev, framebuffer, size) != size) {
    syserror("Error writing image!", error_text, text_len);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<vl_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1040 <write@plt>
cmp    -0x28(%rbp),%eax
je     1181 <vl_copy+0x61>
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xe90(%rip),%rdi
call   1030 <syserror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1188 <vl_copy+0x68>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vl_copy>:
push   %rbp
push   %r14
push   %rbx
mov    %r9d,%r14d
mov    %r8,%rbx
mov    %edx,%ebp
imul   %ecx,%ebp
shl    $0x2,%ebp
mov    %ebp,%edx
call   1040 <write@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ebp,%ecx
je     1158 <vl_copy+0x38>
lea    0xeb5(%rip),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <syserror@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Error writing image!\00"
define i32 @vl_copy(i32 %0, i8* %1, i32 %2, i32 %3, i8* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i32 %5, i32* %13
%15 = load i32, i32* %10
%16 = load i32, i32* %11
%17 = mul nsw i32 %15, %16
%18 = mul nsw i32 %17, 4
store i32 %18, i32* %14
%19 = load i32, i32* %8
%20 = load i8*, i8** %9
%21 = load i32, i32* %14
%22 = call i32 @write(i32 %19, i8* %20, i32 %21)
%23 = load i32, i32* %14
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %29
25: ; preds = %6
%26 = load i8*, i8** %12
%27 = load i32, i32* %13
%28 = call i32 @syserror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %26, i32 %27)
store i32 0, i32* %7
br label %30
29: ; preds = %6
store i32 1, i32* %7
br label %30
30: ; preds = %29, %25
%31 = load i32, i32* %7
ret i32 %31
}

LLVM IR (-O2):
@.str = [21 x i8] c"Error writing image!\00"
define i32 @vl_copy(i32 %0, i8* nocapture %1, i32 %2, i32 %3, i8* %4, i32 %5) {
%7 = shl i32 %2, 2
%8 = mul i32 %7, %3
%9 = tail call i32 @write(i32 %0, i8* %1, i32 %8)
%10 = icmp eq i32 %9, %8
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = tail call i32 @syserror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %5)
br label %13
13: ; preds = %6, %11
%14 = phi i32 [ 0, %11 ], [ 1, %6 ]
ret i32 %14
}