#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*/ np_draw(unsigned int, unsigned int, char);
int /*<<< orphan*/ np_set_cursor_pos(unsigned int, unsigned int);
unsigned int strlen(char *);
void np_draw_string(unsigned x, unsigned y, char *s) {
  unsigned len = strlen(s);
  unsigned i = 0;
  while (i < len) {
    np_set_cursor_pos(x, y);
    np_draw(x, y, s[i]);
    ++x;
    ++i;
  }
}


x86 assembly (clang, -O0):
<np_draw_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1199 <np_draw_string+0x69>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <np_set_cursor_pos@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
movsbl (%rax,%rcx,1),%edx
call   1040 <np_draw@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1155 <np_draw_string+0x25>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<np_draw_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%r13d
mov    %edi,%r14d
mov    %rdx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     1186 <np_draw_string+0x56>
mov    %eax,%r12d
mov    %r14d,%r14d
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
lea    (%r14,%rbp,1),%ebx
mov    %ebx,%edi
mov    %r13d,%esi
call   1050 <np_set_cursor_pos@plt>
movsbl (%r15,%rbp,1),%edx
mov    %ebx,%edi
mov    %r13d,%esi
call   1040 <np_draw@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1160 <np_draw_string+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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