#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*/ vga_putch_at(char const, unsigned short, int /*<<< orphan*/);
void vga_puts(const char *str, int len, unsigned short y, unsigned short x) {
  int i = 0;
  for (i = 0; i < len; i++)
    vga_putch_at(str[i], y, x++);
}


x86 assembly (clang, -O0):
<vga_puts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cx,%ax
mov    %dx,%cx
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %cx,-0xe(%rbp)
mov    %ax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1181 <vga_puts+0x71>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0xe(%rbp),%ax
mov    -0x10(%rbp),%dx
mov    %dx,%si
add    $0x1,%si
mov    %si,-0x10(%rbp)
movzwl %dx,%edx
movsbl %cl,%edi
movzwl %ax,%esi
call   1030 <vga_putch_at@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113b <vga_puts+0x2b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vga_puts>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    114c <vga_puts+0x3c>
mov    %rdi,%r14
mov    %esi,%r15d
movzwl %cx,%r12d
xor    %ebx,%ebx
movzwl %dx,%ebp
nopl   0x0(%rax,%rax,1)
lea    (%r12,%rbx,1),%eax
movsbl (%r14,%rbx,1),%edi
movzwl %ax,%edx
mov    %ebp,%esi
call   1030 <vga_putch_at@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <vga_puts+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @vga_puts(i8* %0, i32 %1, i16 zeroext %2, i16 zeroext %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i16
%8 = alloca i16
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i16 %2, i16* %7
store i16 %3, i16* %8
store i32 0, i32* %9
store i32 0, i32* %9
br label %10
10: ; preds = %25, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = load i32, i32* %9
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = load i16, i16* %7
%21 = load i16, i16* %8
%22 = add i16 %21, 1
store i16 %22, i16* %8
%23 = zext i16 %21 to i32
%24 = call i32 @vga_putch_at(i8 signext %19, i16 zeroext %20, i32 %23)
br label %25
25: ; preds = %14
%26 = load i32, i32* %9
%27 = add nsw i32 %26, 1
store i32 %27, i32* %9
br label %10
28: ; preds = %10
ret void
}

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