#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*/ fmt_buffer;

/* Variables and functions */
int /*<<< orphan*/ csi(char *);
int snprintf(char *, int, char const *, unsigned int, ...);
void cursor_move(unsigned x, unsigned y) {
  const char *fmt_pos = "%d;%dH";
  int len_x_fmt = snprintf(NULL, 0, fmt_pos, x);
  int len_y_fmt = snprintf(NULL, 0, fmt_pos, y);
  char fmt_buffer[len_x_fmt + len_y_fmt + 1];
  snprintf(fmt_buffer, sizeof(fmt_buffer), fmt_pos, x, y);
  csi(fmt_buffer);
}


x86 assembly (clang, -O0):
<cursor_move>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    0xecb(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x4(%rbp),%ecx
xor    %esi,%esi
mov    %esi,-0x38(%rbp)
mov    %esi,%edi
mov    %rdi,-0x40(%rbp)
mov    %sil,%al
mov    %al,-0x31(%rbp)
call   1040 <snprintf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    %eax,%ecx
mov    -0x31(%rbp),%al
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%ecx
call   1040 <snprintf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
mov    %edx,%eax
lea    0x1(%rax,%rcx,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
mov    -0x4(%rbp),%ecx
mov    -0x8(%rbp),%r8d
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <csi@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cursor_move>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %edi,%r12d
lea    0xec8(%rip),%r15
xor    %edi,%edi
xor    %esi,%esi
mov    %r15,%rdx
mov    %r12d,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %eax,%ebx
xor    %edi,%edi
xor    %esi,%esi
mov    %r15,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    (%rbx,%rax,1),%esi
add    $0x1,%esi
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r12d,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <csi@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d;%dH\00"
define void @cursor_move(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %5
%10 = load i8*, i8** %5
%11 = load i32, i32* %3
%12 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* null, i32 0, i8* %10, i32 %11)
store i32 %12, i32* %6
%13 = load i8*, i8** %5
%14 = load i32, i32* %4
%15 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* null, i32 0, i8* %13, i32 %14)
store i32 %15, i32* %7
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = add nsw i32 %16, %17
%19 = add nsw i32 %18, 1
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %8
%22 = alloca i8, i64 %20
store i64 %20, i64* %9
%23 = trunc i64 %20 to i32
%24 = load i8*, i8** %5
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %22, i32 %23, i8* %24, i32 %25, i32 %26)
%28 = call i32 @csi(i8* %22)
%29 = load i8*, i8** %8
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d;%dH\00"
define void @cursor_move(i32 %0, i32 %1) {
%3 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* null, i32 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* null, i32 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %1)
%5 = add i32 %3, 1
%6 = add i32 %5, %4
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %8, i32 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
%10 = call i32 @csi(i8* %8)
ret void
}