#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 pos;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
scalar_t__ wMalloc(int);
scalar_t__ wPopNumber();
char *wPopString();
int /*<<< orphan*/ wPushString(char *);
int /*<<< orphan*/ wPushStringCopy(char *);
void wBasRight() {
  int pos, len, newLen;
  char *string, *right;
  pos = (int)wPopNumber();
  string = wPopString();
  len = strlen(string);
  if (pos >= len) {
    wPushString(string);
    return;
  }
  if (pos < 1) {
    free(string);
    wPushStringCopy("");
    return;
  }
  newLen = (pos) + 1;
  right = (char *)wMalloc((len - newLen) + 1);
  memcpy(right, string + (len - pos), newLen);
  wPushString(right);
  free(string);
}


x86 assembly (clang, -O0):
<wBasRight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1060 <wPopNumber@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1040 <wPopString@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     11c3 <wBasRight+0x43>
mov    -0x18(%rbp),%rdi
call   10a0 <wPushString@plt>
jmp    122f <wBasRight+0xaf>
cmpl   $0x1,-0x4(%rbp)
jge    11e7 <wBasRight+0x67>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe23(%rip),%rdi
call   1080 <wPushStringCopy@plt>
jmp    122f <wBasRight+0xaf>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
sub    -0xc(%rbp),%edi
add    $0x1,%edi
call   1090 <wMalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%eax
sub    -0x4(%rbp),%eax
cltq
add    %rax,%rsi
mov    -0xc(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <wPushString@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wBasRight>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <wPopNumber@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <wPopString@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
sub    %ebx,%ebp
jle    11e7 <wBasRight+0x67>
test   %ebx,%ebx
jle    11f9 <wBasRight+0x79>
add    $0x1,%ebx
mov    %ebp,%edi
call   1090 <wMalloc@plt>
mov    %rax,%r15
movslq %ebp,%rax
mov    %r14,%rsi
add    %rax,%rsi
mov    %r15,%rdi
mov    %ebx,%edx
call   1070 <memcpy@plt>
mov    %r15,%rdi
call   10a0 <wPushString@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <wPushString@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xdf8(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <wPushStringCopy@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define void @wBasRight() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = call i64 (...) @wPopNumber()
%7 = trunc i64 %6 to i32
store i32 %7, i32* %1
%8 = call i8* (...) @wPopString()
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %2
%11 = load i32, i32* %1
%12 = load i32, i32* %2
%13 = icmp sge i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = load i8*, i8** %4
%16 = call i32 @wPushString(i8* %15)
br label %46
17: ; preds = %0
%18 = load i32, i32* %1
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i8*, i8** %4
%22 = call i32 @free(i8* %21)
%23 = call i32 @wPushStringCopy(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %46
24: ; preds = %17
%25 = load i32, i32* %1
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = sub nsw i32 %27, %28
%30 = add nsw i32 %29, 1
%31 = call i64 @wMalloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %5
%33 = load i8*, i8** %5
%34 = load i8*, i8** %4
%35 = load i32, i32* %2
%36 = load i32, i32* %1
%37 = sub nsw i32 %35, %36
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %34, i64 %38
%40 = load i32, i32* %3
%41 = call i32 @memcpy(i8* %33, i8* %39, i32 %40)
%42 = load i8*, i8** %5
%43 = call i32 @wPushString(i8* %42)
%44 = load i8*, i8** %4
%45 = call i32 @free(i8* %44)
br label %46
46: ; preds = %24, %20, %14
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define void @wBasRight() {
%1 = tail call i64 (...) @wPopNumber()
%2 = trunc i64 %1 to i32
%3 = tail call i8* (...) @wPopString()
%4 = tail call i32 @strlen(i8* %3)
%5 = icmp sgt i32 %4, %2
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = tail call i32 @wPushString(i8* %3)
br label %23
8: ; preds = %0
%9 = icmp slt i32 %2, 1
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = tail call i32 @free(i8* %3)
%12 = tail call i32 @wPushStringCopy(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %23
13: ; preds = %8
%14 = add nuw nsw i32 %2, 1
%15 = sub i32 %4, %2
%16 = tail call i64 @wMalloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
%18 = sext i32 %15 to i64
%19 = getelementptr inbounds i8, i8* %3, i64 %18
%20 = tail call i32 @memcpy(i8* %17, i8* %19, i32 %14)
%21 = tail call i32 @wPushString(i8* %17)
%22 = tail call i32 @free(i8* %3)
br label %23
23: ; preds = %13, %10, %6
ret void
}