#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*/ COLS;
int /*<<< orphan*/ LINES;
int /*<<< orphan*/ addch(char const);
int clip(int, int /*<<< orphan*/);
int /*<<< orphan*/ move(int, int);
void blast(int x, int y, const char *buffer, int length) {
  int x1 = clip(x, COLS);
  int y1 = clip(y, LINES);
  int i, L = length;
  move(y1, x1);
  for (i = 0; i < L; ++i)
    addch(buffer[i]);
}


x86 assembly (clang, -O0):
<blast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
call   1030 <clip@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
call   1030 <clip@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <move@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11b0 <blast+0x80>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <addch@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1185 <blast+0x55>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blast>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %rdx,%r12
mov    %esi,%r15d
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
call   1030 <clip@plt>
mov    %eax,%ebp
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   1030 <clip@plt>
mov    %eax,%edi
mov    %ebp,%esi
call   1050 <move@plt>
test   %r14d,%r14d
jle    1193 <blast+0x63>
mov    %r14d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r12,%rbx,1),%edi
call   1040 <addch@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <blast+0x50>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@COLS = global i32 0
@LINES = global i32 0
define void @blast(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%13 = load i32, i32* %5
%14 = load i32, i32* @COLS
%15 = call i32 @clip(i32 %13, i32 %14)
store i32 %15, i32* %9
%16 = load i32, i32* %6
%17 = load i32, i32* @LINES
%18 = call i32 @clip(i32 %16, i32 %17)
store i32 %18, i32* %10
%19 = load i32, i32* %8
store i32 %19, i32* %12
%20 = load i32, i32* %10
%21 = load i32, i32* %9
%22 = call i32 @move(i32 %20, i32 %21)
store i32 0, i32* %11
br label %23
23: ; preds = %34, %4
%24 = load i32, i32* %11
%25 = load i32, i32* %12
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %37
27: ; preds = %23
%28 = load i8*, i8** %7
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = call i32 @addch(i8 signext %32)
br label %34
34: ; preds = %27
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 1
store i32 %36, i32* %11
br label %23
37: ; preds = %23
ret void
}

LLVM IR (-O2):
@COLS = global i32 0
@LINES = global i32 0
define void @blast(i32 %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = load i32, i32* @COLS
%6 = tail call i32 @clip(i32 %0, i32 %5)
%7 = load i32, i32* @LINES
%8 = tail call i32 @clip(i32 %1, i32 %7)
%9 = tail call i32 @move(i32 %8, i32 %6)
%10 = icmp sgt i32 %3, 0
br i1 %10, label %11, label %20
11: ; preds = %4
%12 = zext i32 %3 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %18, %13 ]
%15 = getelementptr inbounds i8, i8* %2, i64 %14
%16 = load i8, i8* %15
%17 = tail call i32 @addch(i8 signext %16)
%18 = add nuw nsw i64 %14, 1
%19 = icmp eq i64 %18, %12
br i1 %19, label %20, label %13
20: ; preds = %13, %4
ret void
}