#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
unsigned int sprintf_s(char *, int, char *, int, int);
int /*<<< orphan*/ stdout;
unsigned int write(int /*<<< orphan*/, char *, unsigned int);
int term_cursor_move(int x, int y) {
  char buf[32];
  unsigned int n = sprintf_s(buf, sizeof(buf), "\x1b[%i;%iH", y + 1, x + 1);
  return write(stdout, buf, n + 1) != n + 1;
}


x86 assembly (clang, -O0):
<term_cursor_move>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
mov    -0x4(%rbp),%r8d
add    $0x1,%r8d
mov    $0x20,%esi
lea    0xeb4(%rip),%rdx
call   1030 <sprintf_s@plt>
mov    %eax,-0x34(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
add    $0x1,%edx
call   1040 <write@plt>
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<term_cursor_move>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
lea    0x1(%rsi),%ecx
lea    0x1(%rdi),%r8d
lea    0xecc(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <sprintf_s@plt>
mov    %eax,%ebp
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
add    $0x1,%ebp
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
xor    %ecx,%ecx
cmp    %ebp,%eax
setne  %cl
mov    %ecx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"\1B[%i;%iH\00"
@stdout = global i32 0
define i32 @term_cursor_move(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [32 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* %4
%9 = add nsw i32 %8, 1
%10 = load i32, i32* %3
%11 = add nsw i32 %10, 1
%12 = call i32 @sprintf_s(i8* %7, i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* @stdout
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%15 = load i32, i32* %6
%16 = add i32 %15, 1
%17 = call i32 @write(i32 %13, i8* %14, i32 %16)
%18 = load i32, i32* %6
%19 = add i32 %18, 1
%20 = icmp ne i32 %17, %19
%21 = zext i1 %20 to i32
ret i32 %21
}

LLVM IR (-O2):
@.str = [9 x i8] c"\1B[%i;%iH\00"
@stdout = global i32 0
define i32 @term_cursor_move(i32 %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = add nsw i32 %1, 1
%6 = add nsw i32 %0, 1
%7 = call i32 @sprintf_s(i8* %4, i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%8 = load i32, i32* @stdout
%9 = add i32 %7, 1
%10 = call i32 @write(i32 %8, i8* %4, i32 %9)
%11 = icmp ne i32 %10, %9
%12 = zext i1 %11 to i32
ret i32 %12
}