#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 abs(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ put_pixel(int, int);
void bresenham(int xa, int ya, int xb, int yb) {
  printf("Bresenham's Line drawing algorithm");
  char c;
  put_pixel(xa, ya);
  int i;
  int del_x = abs(xb - xa);
  int del_y = abs(yb - ya);
  int p0 = 2 * del_y - del_x;
  printf("%d\n", p0);
  for (i = 1; i < xb; i++) {
    if (p0 < 0) {
      xa = xa + 1;
      put_pixel(xa, ya);
      p0 = p0 + 2 * del_y;
    } else {
      xa = xa + 1;
      ya = ya + 1;
      put_pixel(xa, ya);
      p0 = p0 + 2 * del_y - 2 * del_x;
    }
  }
}


x86 assembly (clang, -O0):
<bresenham>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <put_pixel@plt>
mov    -0xc(%rbp),%edi
sub    -0x4(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
sub    -0x8(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1220 <bresenham+0xf0>
cmpl   $0x0,-0x24(%rbp)
jge    11da <bresenham+0xaa>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <put_pixel@plt>
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
jmp    120d <bresenham+0xdd>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <put_pixel@plt>
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
jmp    1212 <bresenham+0xe2>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119d <bresenham+0x6d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bresenham>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%ebx
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%edi
mov    %r14d,%esi
call   1040 <put_pixel@plt>
mov    %ebx,%eax
sub    %ebp,%eax
mov    %eax,%r12d
neg    %r12d
cmovs  %eax,%r12d
sub    %r14d,%r15d
mov    %r15d,%r13d
neg    %r13d
cmovs  %r15d,%r13d
add    %r13d,%r13d
mov    %r13d,%r15d
sub    %r12d,%r15d
lea    0xeab(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x2,%ebx
jl     11d0 <bresenham+0xb0>
add    %r12d,%r12d
neg    %r12d
add    $0x1,%ebp
add    $0xffffffff,%ebx
jmp    11bc <bresenham+0x9c>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r14d
mov    %ebp,%edi
mov    %r14d,%esi
call   1040 <put_pixel@plt>
add    %r13d,%r15d
add    %r12d,%r15d
add    $0x1,%ebp
add    $0xffffffff,%ebx
je     11d0 <bresenham+0xb0>
test   %r15d,%r15d
jns    11a0 <bresenham+0x80>
mov    %ebp,%edi
mov    %r14d,%esi
call   1040 <put_pixel@plt>
add    %r13d,%r15d
jmp    11b4 <bresenham+0x94>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Bresenham's Line drawing algorithm\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define void @bresenham(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = call i32 @put_pixel(i32 %15, i32 %16)
%18 = load i32, i32* %7
%19 = load i32, i32* %5
%20 = sub nsw i32 %18, %19
%21 = call i32 @abs(i32 %20)
store i32 %21, i32* %11
%22 = load i32, i32* %8
%23 = load i32, i32* %6
%24 = sub nsw i32 %22, %23
%25 = call i32 @abs(i32 %24)
store i32 %25, i32* %12
%26 = load i32, i32* %12
%27 = mul nsw i32 2, %26
%28 = load i32, i32* %11
%29 = sub nsw i32 %27, %28
store i32 %29, i32* %13
%30 = load i32, i32* %13
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %30)
store i32 1, i32* %10
br label %32
32: ; preds = %65, %4
%33 = load i32, i32* %10
%34 = load i32, i32* %7
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %68
36: ; preds = %32
%37 = load i32, i32* %13
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %36
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
%42 = load i32, i32* %5
%43 = load i32, i32* %6
%44 = call i32 @put_pixel(i32 %42, i32 %43)
%45 = load i32, i32* %13
%46 = load i32, i32* %12
%47 = mul nsw i32 2, %46
%48 = add nsw i32 %45, %47
store i32 %48, i32* %13
br label %64
49: ; preds = %36
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %5
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
%54 = load i32, i32* %5
%55 = load i32, i32* %6
%56 = call i32 @put_pixel(i32 %54, i32 %55)
%57 = load i32, i32* %13
%58 = load i32, i32* %12
%59 = mul nsw i32 2, %58
%60 = add nsw i32 %57, %59
%61 = load i32, i32* %11
%62 = mul nsw i32 2, %61
%63 = sub nsw i32 %60, %62
store i32 %63, i32* %13
br label %64
64: ; preds = %49, %39
br label %65
65: ; preds = %64
%66 = load i32, i32* %10
%67 = add nsw i32 %66, 1
store i32 %67, i32* %10
br label %32
68: ; preds = %32
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"Bresenham's Line drawing algorithm\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define void @bresenham(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @put_pixel(i32 %0, i32 %1)
%7 = sub nsw i32 %2, %0
%8 = tail call i32 @llvm.abs.i32(i32 %7, i1 true)
%9 = sub nsw i32 %3, %1
%10 = tail call i32 @llvm.abs.i32(i32 %9, i1 true)
%11 = shl nuw nsw i32 %10, 1
%12 = sub nsw i32 %11, %8
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp sgt i32 %2, 1
br i1 %14, label %15, label %37
15: ; preds = %4
%16 = mul i32 %8, -2
br label %17
17: ; preds = %15, %32
%18 = phi i32 [ %12, %15 ], [ %34, %32 ]
%19 = phi i32 [ %0, %15 ], [ %23, %32 ]
%20 = phi i32 [ %1, %15 ], [ %33, %32 ]
%21 = phi i32 [ 1, %15 ], [ %35, %32 ]
%22 = icmp slt i32 %18, 0
%23 = add nsw i32 %19, 1
br i1 %22, label %24, label %27
24: ; preds = %17
%25 = tail call i32 @put_pixel(i32 %23, i32 %20)
%26 = add nsw i32 %18, %11
br label %32
27: ; preds = %17
%28 = add nsw i32 %20, 1
%29 = tail call i32 @put_pixel(i32 %23, i32 %28)
%30 = add nsw i32 %18, %11
%31 = add i32 %30, %16
br label %32
32: ; preds = %24, %27
%33 = phi i32 [ %20, %24 ], [ %28, %27 ]
%34 = phi i32 [ %26, %24 ], [ %31, %27 ]
%35 = add nuw nsw i32 %21, 1
%36 = icmp eq i32 %35, %2
br i1 %36, label %37, label %17
37: ; preds = %32, %4
ret void
}