#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_cursor_offset();
int get_offset(int, int);
int get_offset_col(int);
int get_offset_row(int);
int /*<<< orphan*/ int_to_ascii(int, char *);
int /*<<< orphan*/ kprint(char *);
void get_cursor_pos() {
  char rowstr[2];
  char colstr[2];
  char offsetstr[4];
  int coffset = get_cursor_offset();
  int row = get_offset_row(coffset);
  int col = get_offset_col(coffset);
  int offset = get_offset(col, row);
  int nrow = get_offset_row(offset);
  int ncol = get_offset_col(offset);
  int_to_ascii(nrow, rowstr);
  int_to_ascii(ncol, colstr);
  int_to_ascii(offset, offsetstr);
  kprint(offsetstr);
  kprint("\n");
  kprint(rowstr);
  kprint("\n");
  kprint(colstr);
}


x86 assembly (clang, -O0):
<get_cursor_pos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <get_cursor_offset@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <get_offset_row@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <get_offset_col@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1080 <get_offset@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1070 <get_offset_row@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <get_offset_col@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x2(%rbp),%rsi
call   1060 <int_to_ascii@plt>
mov    -0x20(%rbp),%edi
lea    -0x4(%rbp),%rsi
call   1060 <int_to_ascii@plt>
mov    -0x18(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1060 <int_to_ascii@plt>
lea    -0x8(%rbp),%rdi
call   1050 <kprint@plt>
lea    0xe20(%rip),%rdi
call   1050 <kprint@plt>
lea    -0x2(%rbp),%rdi
call   1050 <kprint@plt>
lea    0xe0b(%rip),%rdi
call   1050 <kprint@plt>
lea    -0x4(%rbp),%rdi
call   1050 <kprint@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cursor_pos>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1040 <get_cursor_offset@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <get_offset_row@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <get_offset_col@plt>
mov    %eax,%edi
mov    %ebp,%esi
call   1080 <get_offset@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <get_offset_row@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <get_offset_col@plt>
mov    %eax,%r14d
lea    0xa(%rsp),%r15
mov    %ebp,%edi
mov    %r15,%rsi
call   1060 <int_to_ascii@plt>
lea    0x8(%rsp),%r12
mov    %r14d,%edi
mov    %r12,%rsi
call   1060 <int_to_ascii@plt>
lea    0xc(%rsp),%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
call   1060 <int_to_ascii@plt>
mov    %rbp,%rdi
call   1050 <kprint@plt>
lea    0xe20(%rip),%rbx
mov    %rbx,%rdi
call   1050 <kprint@plt>
mov    %r15,%rdi
call   1050 <kprint@plt>
mov    %rbx,%rdi
call   1050 <kprint@plt>
mov    %r12,%rdi
call   1050 <kprint@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define void @get_cursor_pos() {
%1 = alloca [2 x i8]
%2 = alloca [2 x i8]
%3 = alloca [4 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = call i32 (...) @get_cursor_offset()
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = call i32 @get_offset_row(i32 %11)
store i32 %12, i32* %5
%13 = load i32, i32* %4
%14 = call i32 @get_offset_col(i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = load i32, i32* %5
%17 = call i32 @get_offset(i32 %15, i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = call i32 @get_offset_row(i32 %18)
store i32 %19, i32* %8
%20 = load i32, i32* %7
%21 = call i32 @get_offset_col(i32 %20)
store i32 %21, i32* %9
%22 = load i32, i32* %8
%23 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%24 = call i32 @int_to_ascii(i32 %22, i8* %23)
%25 = load i32, i32* %9
%26 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%27 = call i32 @int_to_ascii(i32 %25, i8* %26)
%28 = load i32, i32* %7
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%30 = call i32 @int_to_ascii(i32 %28, i8* %29)
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%32 = call i32 @kprint(i8* %31)
%33 = call i32 @kprint(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%34 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%35 = call i32 @kprint(i8* %34)
%36 = call i32 @kprint(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%37 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%38 = call i32 @kprint(i8* %37)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define void @get_cursor_pos() {
%1 = alloca [2 x i8]
%2 = alloca [2 x i8]
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%7 = tail call i32 (...) @get_cursor_offset()
%8 = tail call i32 @get_offset_row(i32 %7)
%9 = tail call i32 @get_offset_col(i32 %7)
%10 = tail call i32 @get_offset(i32 %9, i32 %8)
%11 = tail call i32 @get_offset_row(i32 %10)
%12 = tail call i32 @get_offset_col(i32 %10)
%13 = call i32 @int_to_ascii(i32 %11, i8* %4)
%14 = call i32 @int_to_ascii(i32 %12, i8* %5)
%15 = call i32 @int_to_ascii(i32 %10, i8* %6)
%16 = call i32 @kprint(i8* %6)
%17 = call i32 @kprint(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @kprint(i8* %4)
%19 = call i32 @kprint(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @kprint(i8* %5)
ret void
}