#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_left(int n) {
  int column = get_column();
  while (n--) {
    if (column > 1) {
      write_assert(1, "\e[1D", 4);
      column--;
    } else {
      write_assert(1, "\e[1A\e[999C", 10);
      column = get_column();
    }
  }
}


x86 assembly (clang, -O0):
<move_left>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <get_column@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
je     119c <move_left+0x7c>
cmpl   $0x1,-0x8(%rbp)
jle    1177 <move_left+0x57>
mov    $0x1,%edi
lea    0xea1(%rip),%rsi
mov    $0x4,%edx
call   1030 <write_assert@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1197 <move_left+0x77>
mov    $0x1,%edi
lea    0xe82(%rip),%rsi
mov    $0xa,%edx
call   1030 <write_assert@plt>
mov    $0x0,%al
call   1040 <get_column@plt>
mov    %eax,-0x8(%rbp)
jmp    1135 <move_left+0x15>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<move_left>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <get_column@plt>
test   %ebx,%ebx
je     118b <move_left+0x6b>
mov    %eax,%ebp
lea    0xec3(%rip),%r14
lea    0xec1(%rip),%r15
jmp    116a <move_left+0x4a>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rsi
mov    $0xa,%edx
call   1030 <write_assert@plt>
xor    %eax,%eax
call   1040 <get_column@plt>
mov    %eax,%ebp
test   %ebx,%ebx
je     118b <move_left+0x6b>
add    $0xffffffff,%ebx
mov    $0x1,%edi
cmp    $0x2,%ebp
jl     1150 <move_left+0x30>
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <write_assert@plt>
add    $0xffffffff,%ebp
test   %ebx,%ebx
jne    116a <move_left+0x4a>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\1B[1D\00"
@.str.1 = [11 x i8] c"\1B[1A\1B[999C\00"
define void @move_left(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 (...) @get_column()
store i32 %4, i32* %3
br label %5
5: ; preds = %19, %1
%6 = load i32, i32* %2
%7 = add nsw i32 %6, -1
store i32 %7, i32* %2
%8 = icmp ne i32 %6, 0
br i1 %8, label %9, label %20
9: ; preds = %5
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = call i32 @write_assert(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%14 = load i32, i32* %3
%15 = add nsw i32 %14, -1
store i32 %15, i32* %3
br label %19
16: ; preds = %9
%17 = call i32 @write_assert(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 10)
%18 = call i32 (...) @get_column()
store i32 %18, i32* %3
br label %19
19: ; preds = %16, %12
br label %5
20: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"\1B[1D\00"
@.str.1 = [11 x i8] c"\1B[1A\1B[999C\00"
define void @move_left(i32 %0) {
%2 = tail call i32 (...) @get_column()
%3 = icmp eq i32 %0, 0
br i1 %3, label %18, label %4
4: ; preds = %1, %15
%5 = phi i32 [ %7, %15 ], [ %0, %1 ]
%6 = phi i32 [ %16, %15 ], [ %2, %1 ]
%7 = add nsw i32 %5, -1
%8 = icmp sgt i32 %6, 1
br i1 %8, label %9, label %12
9: ; preds = %4
%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 = add nsw i32 %6, -1
br label %15
12: ; preds = %4
%13 = tail call i32 @write_assert(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 10)
%14 = tail call i32 (...) @get_column()
br label %15
15: ; preds = %12, %9
%16 = phi i32 [ %11, %9 ], [ %14, %12 ]
%17 = icmp eq i32 %7, 0
br i1 %17, label %18, label %4
18: ; preds = %15, %1
ret void
}