#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 */
unsigned short abs(short);
int /*<<< orphan*/ line(unsigned short volatile *, short, short, short, short,
                        unsigned short, unsigned int);
void drawLine(volatile unsigned short *vram, short xs, short ys, short xe,
              short ye, unsigned color) {
  short dx = xe - xs;
  short dy = ye - ys;
  unsigned short count = (abs(dx) >= abs(dy)) ? abs(dx) : abs(dy);
  line(vram, xs, ys, dx, dy, count, color);
}


x86 assembly (clang, -O0):
<drawLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8w,%ax
mov    %rdi,-0x8(%rbp)
mov    %si,-0xa(%rbp)
mov    %dx,-0xc(%rbp)
mov    %cx,-0xe(%rbp)
mov    %ax,-0x10(%rbp)
mov    %r9d,-0x14(%rbp)
movswl -0xe(%rbp),%eax
movswl -0xa(%rbp),%ecx
sub    %ecx,%eax
mov    %ax,-0x16(%rbp)
movswl -0x10(%rbp),%eax
movswl -0xc(%rbp),%ecx
sub    %ecx,%eax
mov    %ax,-0x18(%rbp)
movswl -0x16(%rbp),%edi
call   1030 <abs@plt>
movzwl %ax,%eax
mov    %eax,-0x20(%rbp)
movswl -0x18(%rbp),%edi
call   1030 <abs@plt>
mov    %ax,%cx
mov    -0x20(%rbp),%eax
movzwl %cx,%ecx
cmp    %ecx,%eax
jl     119d <drawLine+0x7d>
movswl -0x16(%rbp),%edi
call   1030 <abs@plt>
movzwl %ax,%eax
mov    %eax,-0x24(%rbp)
jmp    11ac <drawLine+0x8c>
movswl -0x18(%rbp),%edi
call   1030 <abs@plt>
movzwl %ax,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %ax,-0x1a(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xa(%rbp),%si
mov    -0xc(%rbp),%dx
mov    -0x16(%rbp),%cx
mov    -0x18(%rbp),%r8w
mov    -0x1a(%rbp),%r9w
mov    -0x14(%rbp),%eax
movswl %si,%esi
movswl %dx,%edx
movswl %cx,%ecx
movswl %r8w,%r8d
movzwl %r9w,%r9d
mov    %eax,(%rsp)
call   1040 <line@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drawLine>:
push   %rax
sub    %esi,%ecx
sub    %edx,%r8d
mov    %ecx,%eax
neg    %ax
cmovs  %cx,%ax
mov    %r8d,%r10d
neg    %r10w
cmovs  %r8w,%r10w
cmp    %r10w,%ax
cmovb  %r10d,%eax
mov    %r9d,(%rsp)
movzwl %ax,%r9d
movswl %cx,%ecx
movswl %r8w,%r8d
call   1030 <line@plt>
pop    %rax
ret

LLVM IR (-O0):
define void @drawLine(i16* %0, i16 signext %1, i16 signext %2, i16 signext %3, i16 signext %4, i32 %5) {
%7 = alloca i16*
%8 = alloca i16
%9 = alloca i16
%10 = alloca i16
%11 = alloca i16
%12 = alloca i32
%13 = alloca i16
%14 = alloca i16
%15 = alloca i16
store i16* %0, i16** %7
store i16 %1, i16* %8
store i16 %2, i16* %9
store i16 %3, i16* %10
store i16 %4, i16* %11
store i32 %5, i32* %12
%16 = load i16, i16* %10
%17 = sext i16 %16 to i32
%18 = load i16, i16* %8
%19 = sext i16 %18 to i32
%20 = sub nsw i32 %17, %19
%21 = trunc i32 %20 to i16
store i16 %21, i16* %13
%22 = load i16, i16* %11
%23 = sext i16 %22 to i32
%24 = load i16, i16* %9
%25 = sext i16 %24 to i32
%26 = sub nsw i32 %23, %25
%27 = trunc i32 %26 to i16
store i16 %27, i16* %14
%28 = load i16, i16* %13
%29 = call zeroext i16 @abs(i16 signext %28)
%30 = zext i16 %29 to i32
%31 = load i16, i16* %14
%32 = call zeroext i16 @abs(i16 signext %31)
%33 = zext i16 %32 to i32
%34 = icmp sge i32 %30, %33
br i1 %34, label %35, label %39
35: ; preds = %6
%36 = load i16, i16* %13
%37 = call zeroext i16 @abs(i16 signext %36)
%38 = zext i16 %37 to i32
br label %43
39: ; preds = %6
%40 = load i16, i16* %14
%41 = call zeroext i16 @abs(i16 signext %40)
%42 = zext i16 %41 to i32
br label %43
43: ; preds = %39, %35
%44 = phi i32 [ %38, %35 ], [ %42, %39 ]
%45 = trunc i32 %44 to i16
store i16 %45, i16* %15
%46 = load i16*, i16** %7
%47 = load i16, i16* %8
%48 = load i16, i16* %9
%49 = load i16, i16* %13
%50 = load i16, i16* %14
%51 = load i16, i16* %15
%52 = load i32, i32* %12
%53 = call i32 @line(i16* %46, i16 signext %47, i16 signext %48, i16 signext %49, i16 signext %50, i16 zeroext %51, i32 %52)
ret void
}

LLVM IR (-O2):
define void @drawLine(i16* %0, i16 signext %1, i16 signext %2, i16 signext %3, i16 signext %4, i32 %5) {
%7 = sub i16 %3, %1
%8 = sub i16 %4, %2
%9 = tail call i16 @llvm.abs.i16(i16 %7, i1 true)
%10 = tail call i16 @llvm.abs.i16(i16 %8, i1 true)
%11 = icmp ult i16 %9, %10
%12 = select i1 %11, i16 %10, i16 %9
%13 = tail call i32 @line(i16* %0, i16 signext %1, i16 signext %2, i16 signext %7, i16 signext %8, i16 zeroext %12, i32 %5)
ret void
}