#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 get_screen_offset(int, int);
int /*<<< orphan*/ print_char(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ set_cursor(int);
void print(char *str, int row, int col) {
  int offset = get_screen_offset(row, col);
  if (offset != -1)
    set_cursor(offset);
  char *ptr = str;
  while (*ptr != 0)
    print_char(*ptr++, -1, -1);
}


x86 assembly (clang, -O0):
<print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <get_screen_offset@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     1162 <print+0x32>
mov    -0x14(%rbp),%edi
call   1040 <set_cursor@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     119d <print+0x6d>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%edi
mov    $0xffffffff,%edx
mov    %edx,%esi
call   1050 <print_char@plt>
jmp    116a <print+0x3a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print>:
push   %rbx
mov    %rdi,%rbx
mov    %esi,%edi
mov    %edx,%esi
call   1030 <get_screen_offset@plt>
cmp    $0xffffffff,%eax
je     1149 <print+0x19>
mov    %eax,%edi
call   1040 <set_cursor@plt>
mov    (%rbx),%al
test   %al,%al
je     117d <print+0x4d>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
mov    $0xffffffff,%esi
mov    $0xffffffff,%edx
call   1050 <print_char@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <print+0x30>
pop    %rbx
ret

LLVM IR (-O0):
define void @print(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = call i32 @get_screen_offset(i32 %9, i32 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i32, i32* %7
%16 = call i32 @set_cursor(i32 %15)
br label %17
17: ; preds = %14, %3
%18 = load i8*, i8** %4
store i8* %18, i8** %8
br label %19
19: ; preds = %24, %17
%20 = load i8*, i8** %8
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %8
%27 = load i8, i8* %25
%28 = sext i8 %27 to i32
%29 = call i32 @print_char(i32 %28, i32 -1, i32 -1)
br label %19
30: ; preds = %19
ret void
}

LLVM IR (-O2):
define void @print(i8* nocapture %0, i32 %1, i32 %2) {
%4 = tail call i32 @get_screen_offset(i32 %1, i32 %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @set_cursor(i32 %4)
br label %8
8: ; preds = %6, %3
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %8, %11
%12 = phi i8 [ %17, %11 ], [ %9, %8 ]
%13 = phi i8* [ %15, %11 ], [ %0, %8 ]
%14 = sext i8 %12 to i32
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = tail call i32 @print_char(i32 %14, i32 -1, i32 -1)
%17 = load i8, i8* %15
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %11
19: ; preds = %11, %8
ret void
}