#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_column();
int /*<<< orphan*/ write_assert(int, char *, int);
void move_right(int n) {
  int i;
  int column, old_column = get_column();
startover:
  i = n;
  while (i--) {
    write_assert(1, "\e[1C", 4);
  }
  column = get_column();
  if (column - old_column < n) {
    write_assert(1, "\e[1E", 4);
    n = n - column + old_column - 1;
    old_column = 1;
    goto startover;
  }
}


x86 assembly (clang, -O0):
<move_right>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <get_column@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     116a <move_right+0x4a>
mov    $0x1,%edi
lea    0xea5(%rip),%rsi
mov    $0x4,%edx
call   1030 <write_assert@plt>
jmp    113b <move_right+0x1b>
mov    $0x0,%al
call   1040 <get_column@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b4 <move_right+0x94>
mov    $0x1,%edi
lea    0xe76(%rip),%rsi
mov    $0x4,%edx
call   1030 <write_assert@plt>
mov    -0x4(%rbp),%eax
sub    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
jmp    1135 <move_right+0x15>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<move_right>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r12d
xor    %eax,%eax
call   1040 <get_column@plt>
mov    %eax,%r15d
lea    0xec9(%rip),%r14
lea    0xebd(%rip),%rbx
test   %r12d,%r12d
je     1177 <move_right+0x57>
nopl   0x0(%rax,%rax,1)
mov    %r12d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <write_assert@plt>
add    $0xffffffff,%ebp
jne    1160 <move_right+0x40>
xor    %eax,%eax
call   1040 <get_column@plt>
mov    %eax,%ebp
sub    %r15d,%eax
cmp    %r12d,%eax
jge    11af <move_right+0x8f>
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <write_assert@plt>
add    %r15d,%r12d
not    %ebp
add    %ebp,%r12d
mov    $0x1,%r15d
test   %r12d,%r12d
jne    1150 <move_right+0x30>
jmp    1177 <move_right+0x57>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\1B[1C\00"
@.str.1 = [5 x i8] c"\1B[1E\00"
define void @move_right(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i32 (...) @get_column()
store i32 %6, i32* %5
br label %7
7: ; preds = %22, %1
%8 = load i32, i32* %2
store i32 %8, i32* %3
br label %9
9: ; preds = %13, %7
%10 = load i32, i32* %3
%11 = add nsw i32 %10, -1
store i32 %11, i32* %3
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @write_assert(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
br label %9
15: ; preds = %9
%16 = call i32 (...) @get_column()
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = sub nsw i32 %17, %18
%20 = load i32, i32* %2
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %30
22: ; preds = %15
%23 = call i32 @write_assert(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%24 = load i32, i32* %2
%25 = load i32, i32* %4
%26 = sub nsw i32 %24, %25
%27 = load i32, i32* %5
%28 = add nsw i32 %26, %27
%29 = sub nsw i32 %28, 1
store i32 %29, i32* %2
store i32 1, i32* %5
br label %7
30: ; preds = %15
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"\1B[1C\00"
@.str.1 = [5 x i8] c"\1B[1E\00"
define void @move_right(i32 %0) {
%2 = tail call i32 (...) @get_column()
br label %3
3: ; preds = %16, %1
%4 = phi i32 [ %0, %1 ], [ %20, %16 ]
%5 = phi i32 [ %2, %1 ], [ 1, %16 ]
%6 = icmp eq i32 %4, 0
br i1 %6, label %12, label %7
7: ; preds = %3, %7
%8 = phi i32 [ %9, %7 ], [ %4, %3 ]
%9 = add nsw i32 %8, -1
%10 = tail call i32 @write_assert(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%11 = icmp eq i32 %9, 0
br i1 %11, label %12, label %7
12: ; preds = %7, %3
%13 = tail call i32 (...) @get_column()
%14 = sub nsw i32 %13, %5
%15 = icmp slt i32 %14, %4
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = tail call i32 @write_assert(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%18 = add nsw i32 %4, -1
%19 = add i32 %18, %5
%20 = sub i32 %19, %13
br label %3
21: ; preds = %12
ret void
}