#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 */
struct raster {
  int dummy;
};

/* Variables and functions */
int abs(int);
int round(int);
int /*<<< orphan*/ setpixel(struct raster *, int, int, int, int, int);
double sqrt(int);
void drawline(struct raster *ra, int x1, int y1, int x2, int y2, int r, int g,
              int b) {
  double len, dx, dy;
  double j;
  len = sqrt(abs(x2 - x1) * abs(x2 - x1) + abs(y2 - y1) * abs(y2 - y1));
  dx = ((double)(x2 - x1)) / (len);
  dy = ((double)(y2 - y1)) / (len);
  for (j = 0; j <= len; j++) {
    int px, py;
    px = round(x1 + dx * j);
    py = round(y1 + dy * j);
    setpixel(ra, px, py, r, g, b);
  }
}


x86 assembly (clang, -O0):
<drawline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
sub    -0xc(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x54(%rbp)
mov    -0x14(%rbp),%edi
sub    -0xc(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x50(%rbp)
mov    -0x18(%rbp),%edi
sub    -0x10(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%edi
sub    -0x10(%rbp),%edi
call   1030 <abs@plt>
mov    -0x50(%rbp),%edi
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
imul   %ecx,%eax
add    %eax,%edi
call   1060 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1272 <drawline+0x132>
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <round@plt>
mov    %eax,-0x44(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <round@plt>
mov    %eax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x44(%rbp),%esi
mov    -0x48(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    0x10(%rbp),%r8d
mov    0x18(%rbp),%r9d
call   1040 <setpixel@plt>
movsd  0xd9d(%rip),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    11e7 <drawline+0xa7>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drawline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9d,%r12d
mov    %r8d,%ebp
mov    %ecx,%r13d
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
sub    %esi,%r13d
mov    %r13d,%eax
imul   %r13d,%eax
sub    %edx,%ebp
mov    %ebp,%edi
imul   %ebp,%edi
add    %eax,%edi
call   1050 <sqrt@plt>
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x8(%rsp)
ucomisd %xmm1,%xmm0
jb     123b <drawline+0x10b>
mov    %r14d,%eax
mov    0x78(%rsp),%r14d
mov    %r15d,%ecx
mov    0x70(%rsp),%r15d
cvtsi2sd %r13d,%xmm2
movsd  0x8(%rsp),%xmm0
divsd  %xmm0,%xmm2
movsd  %xmm2,0x30(%rsp)
xorps  %xmm2,%xmm2
cvtsi2sd %ebp,%xmm2
cvtsi2sd %ecx,%xmm3
movsd  %xmm3,0x20(%rsp)
divsd  %xmm0,%xmm2
movsd  %xmm2,0x28(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x18(%rsp)
nopl   0x0(%rax)
movsd  %xmm1,0x10(%rsp)
movsd  0x30(%rsp),%xmm0
mulsd  %xmm1,%xmm0
addsd  0x20(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <round@plt>
mov    %eax,%ebp
movsd  0x28(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <round@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
mov    %r12d,%ecx
mov    %r15d,%r8d
mov    %r14d,%r9d
call   1030 <setpixel@plt>
movsd  0x10(%rsp),%xmm1
addsd  0xdd1(%rip),%xmm1
movsd  0x8(%rsp),%xmm0
ucomisd %xmm1,%xmm0
jae    11d0 <drawline+0xa0>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.raster = type { i32 }
define void @drawline(%struct.raster* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca %struct.raster*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca i32
%22 = alloca i32
store %struct.raster* %0, %struct.raster** %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i32 %7, i32* %16
%23 = load i32, i32* %12
%24 = load i32, i32* %10
%25 = sub nsw i32 %23, %24
%26 = call i32 @abs(i32 %25)
%27 = load i32, i32* %12
%28 = load i32, i32* %10
%29 = sub nsw i32 %27, %28
%30 = call i32 @abs(i32 %29)
%31 = mul nsw i32 %26, %30
%32 = load i32, i32* %13
%33 = load i32, i32* %11
%34 = sub nsw i32 %32, %33
%35 = call i32 @abs(i32 %34)
%36 = load i32, i32* %13
%37 = load i32, i32* %11
%38 = sub nsw i32 %36, %37
%39 = call i32 @abs(i32 %38)
%40 = mul nsw i32 %35, %39
%41 = add nsw i32 %31, %40
%42 = call double @sqrt(i32 %41)
store double %42, double* %17
%43 = load i32, i32* %12
%44 = load i32, i32* %10
%45 = sub nsw i32 %43, %44
%46 = sitofp i32 %45 to double
%47 = load double, double* %17
%48 = fdiv double %46, %47
store double %48, double* %18
%49 = load i32, i32* %13
%50 = load i32, i32* %11
%51 = sub nsw i32 %49, %50
%52 = sitofp i32 %51 to double
%53 = load double, double* %17
%54 = fdiv double %52, %53
store double %54, double* %19
store double 0.000000e+00, double* %20
br label %55
55: ; preds = %81, %8
%56 = load double, double* %20
%57 = load double, double* %17
%58 = fcmp ole double %56, %57
br i1 %58, label %59, label %84
59: ; preds = %55
%60 = load i32, i32* %10
%61 = sitofp i32 %60 to double
%62 = load double, double* %18
%63 = load double, double* %20
%64 = call double @llvm.fmuladd.f64(double %62, double %63, double %61)
%65 = fptosi double %64 to i32
%66 = call i32 @round(i32 %65)
store i32 %66, i32* %21
%67 = load i32, i32* %11
%68 = sitofp i32 %67 to double
%69 = load double, double* %19
%70 = load double, double* %20
%71 = call double @llvm.fmuladd.f64(double %69, double %70, double %68)
%72 = fptosi double %71 to i32
%73 = call i32 @round(i32 %72)
store i32 %73, i32* %22
%74 = load %struct.raster*, %struct.raster** %9
%75 = load i32, i32* %21
%76 = load i32, i32* %22
%77 = load i32, i32* %14
%78 = load i32, i32* %15
%79 = load i32, i32* %16
%80 = call i32 @setpixel(%struct.raster* %74, i32 %75, i32 %76, i32 %77, i32 %78, i32 %79)
br label %81
81: ; preds = %59
%82 = load double, double* %20
%83 = fadd double %82, 1.000000e+00
store double %83, double* %20
br label %55
84: ; preds = %55
ret void
}

LLVM IR (-O2):
%struct.raster = type { i32 }
define void @drawline(%struct.raster* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = sub nsw i32 %3, %1
%10 = mul i32 %9, %9
%11 = sub nsw i32 %4, %2
%12 = mul i32 %11, %11
%13 = add nsw i32 %12, %10
%14 = tail call double @sqrt(i32 %13)
%15 = sitofp i32 %9 to double
%16 = fdiv double %15, %14
%17 = sitofp i32 %11 to double
%18 = fdiv double %17, %14
%19 = fcmp ult double %14, 0.000000e+00
br i1 %19, label %34, label %20
20: ; preds = %8
%21 = sitofp i32 %1 to double
%22 = sitofp i32 %2 to double
br label %23
23: ; preds = %20, %23
%24 = phi double [ 0.000000e+00, %20 ], [ %32, %23 ]
%25 = tail call double @llvm.fmuladd.f64(double %16, double %24, double %21)
%26 = fptosi double %25 to i32
%27 = tail call i32 @round(i32 %26)
%28 = tail call double @llvm.fmuladd.f64(double %18, double %24, double %22)
%29 = fptosi double %28 to i32
%30 = tail call i32 @round(i32 %29)
%31 = tail call i32 @setpixel(%struct.raster* %0, i32 %27, i32 %30, i32 %5, i32 %6, i32 %7)
%32 = fadd double %24, 1.000000e+00
%33 = fcmp ugt double %32, %14
br i1 %33, label %34, label %23
34: ; preds = %23, %8
ret void
}