#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*/ tek_ALP();
int /*<<< orphan*/ tek_clear(char const *);
int /*<<< orphan*/ tek_enable(int);
int /*<<< orphan*/ tek_linestyle(int);
int /*<<< orphan*/ tek_point(int, int, int);
int tek_grid_demo(const char *the_title) {
  int y, x;
  int style = 0;
  tek_clear(the_title);
  tek_enable(1);
  for (y = 0; y <= 3072; y += 3072 / 16) {
    tek_linestyle(style++ % 4);
    tek_point(0, y, 0);
    tek_point(1, y, 4096 - 1);
  }
  for (x = 0; x <= 4096; x += 4096 / 16) {
    tek_linestyle(style++ % 4);
    tek_point(0, 0, x);
    tek_point(1, 3072 - 1, x);
  }
  tek_ALP();
  tek_enable(0);
  return (0);
}


x86 assembly (clang, -O0):
<tek_grid_demo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <tek_clear@plt>
mov    $0x1,%edi
call   1070 <tek_enable@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xc00,-0xc(%rbp)
jg     11d2 <tek_grid_demo+0x82>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1060 <tek_linestyle@plt>
mov    -0xc(%rbp),%esi
xor    %edx,%edx
mov    %edx,%edi
call   1050 <tek_point@plt>
mov    -0xc(%rbp),%esi
mov    $0x1,%edi
mov    $0xfff,%edx
call   1050 <tek_point@plt>
mov    -0xc(%rbp),%eax
add    $0xc0,%eax
mov    %eax,-0xc(%rbp)
jmp    117d <tek_grid_demo+0x2d>
movl   $0x0,-0x10(%rbp)
cmpl   $0x1000,-0x10(%rbp)
jg     122e <tek_grid_demo+0xde>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1060 <tek_linestyle@plt>
mov    -0x10(%rbp),%edx
xor    %esi,%esi
mov    %esi,%edi
call   1050 <tek_point@plt>
mov    -0x10(%rbp),%edx
mov    $0x1,%edi
mov    $0xbff,%esi
call   1050 <tek_point@plt>
mov    -0x10(%rbp),%eax
add    $0x100,%eax
mov    %eax,-0x10(%rbp)
jmp    11d9 <tek_grid_demo+0x89>
mov    $0x0,%al
call   1030 <tek_ALP@plt>
xor    %edi,%edi
call   1070 <tek_enable@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tek_grid_demo>:
push   %rbp
push   %rbx
push   %rax
call   1040 <tek_clear@plt>
mov    $0x1,%edi
call   1070 <tek_enable@plt>
xor    %edi,%edi
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%rdi),%ebp
and    $0x3,%edi
call   1060 <tek_linestyle@plt>
xor    %edi,%edi
mov    %ebx,%esi
xor    %edx,%edx
call   1050 <tek_point@plt>
mov    $0x1,%edi
mov    %ebx,%esi
mov    $0xfff,%edx
call   1050 <tek_point@plt>
add    $0xc0,%ebx
mov    %ebp,%edi
cmp    $0x11,%ebp
jne    1170 <tek_grid_demo+0x20>
xor    %ebx,%ebx
mov    $0x11,%edi
nopl   0x0(%rax,%rax,1)
lea    0x1(%rdi),%ebp
and    $0x3,%edi
call   1060 <tek_linestyle@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %ebx,%edx
call   1050 <tek_point@plt>
mov    $0x1,%edi
mov    $0xbff,%esi
mov    %ebx,%edx
call   1050 <tek_point@plt>
add    $0x100,%ebx
mov    %ebp,%edi
cmp    $0x22,%ebp
jne    11b0 <tek_grid_demo+0x60>
xor    %eax,%eax
call   1030 <tek_ALP@plt>
xor    %edi,%edi
call   1070 <tek_enable@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @tek_grid_demo(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
%6 = load i8*, i8** %2
%7 = call i32 @tek_clear(i8* %6)
%8 = call i32 @tek_enable(i32 1)
store i32 0, i32* %3
br label %9
9: ; preds = %21, %1
%10 = load i32, i32* %3
%11 = icmp sle i32 %10, 3072
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = load i32, i32* %5
%14 = add nsw i32 %13, 1
store i32 %14, i32* %5
%15 = srem i32 %13, 4
%16 = call i32 @tek_linestyle(i32 %15)
%17 = load i32, i32* %3
%18 = call i32 @tek_point(i32 0, i32 %17, i32 0)
%19 = load i32, i32* %3
%20 = call i32 @tek_point(i32 1, i32 %19, i32 4095)
br label %21
21: ; preds = %12
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 192
store i32 %23, i32* %3
br label %9
24: ; preds = %9
store i32 0, i32* %4
br label %25
25: ; preds = %37, %24
%26 = load i32, i32* %4
%27 = icmp sle i32 %26, 4096
br i1 %27, label %28, label %40
28: ; preds = %25
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
%31 = srem i32 %29, 4
%32 = call i32 @tek_linestyle(i32 %31)
%33 = load i32, i32* %4
%34 = call i32 @tek_point(i32 0, i32 0, i32 %33)
%35 = load i32, i32* %4
%36 = call i32 @tek_point(i32 1, i32 3071, i32 %35)
br label %37
37: ; preds = %28
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 256
store i32 %39, i32* %4
br label %25
40: ; preds = %25
%41 = call i32 (...) @tek_ALP()
%42 = call i32 @tek_enable(i32 0)
ret i32 0
}

LLVM IR (-O2):
define i32 @tek_grid_demo(i8* %0) {
%2 = tail call i32 @tek_clear(i8* %0)
%3 = tail call i32 @tek_enable(i32 1)
br label %4
4: ; preds = %1, %4
%5 = phi i32 [ 0, %1 ], [ %7, %4 ]
%6 = phi i32 [ 0, %1 ], [ %12, %4 ]
%7 = add nuw nsw i32 %5, 1
%8 = and i32 %5, 3
%9 = tail call i32 @tek_linestyle(i32 %8)
%10 = tail call i32 @tek_point(i32 0, i32 %6, i32 0)
%11 = tail call i32 @tek_point(i32 1, i32 %6, i32 4095)
%12 = add nuw nsw i32 %6, 192
%13 = icmp eq i32 %7, 17
br i1 %13, label %14, label %4
14: ; preds = %4, %14
%15 = phi i32 [ %17, %14 ], [ 17, %4 ]
%16 = phi i32 [ %22, %14 ], [ 0, %4 ]
%17 = add nuw nsw i32 %15, 1
%18 = and i32 %15, 3
%19 = tail call i32 @tek_linestyle(i32 %18)
%20 = tail call i32 @tek_point(i32 0, i32 0, i32 %16)
%21 = tail call i32 @tek_point(i32 1, i32 3071, i32 %16)
%22 = add nuw nsw i32 %16, 256
%23 = icmp eq i32 %17, 34
br i1 %23, label %24, label %14
24: ; preds = %14
%25 = tail call i32 (...) @tek_ALP()
%26 = tail call i32 @tek_enable(i32 0)
ret i32 0
}