#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 /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ wFree(char *);
scalar_t__ wMalloc(int);
scalar_t__ wPopNumber();
char *wPopString();
int /*<<< orphan*/ wPushString(char *);
int /*<<< orphan*/ wPushStringCopy(char *);
void wBasLeft() {
  int pos, len, newLen;
  char *string, *left;
  pos = (int)wPopNumber();
  string = wPopString();
  len = strlen(string);
  if (pos > len - 1) {
    wPushString(string);
    return;
  }
  if (pos < 1) {
    wFree(string);
    wPushStringCopy("");
    return;
  }
  newLen = (pos);
  left = (char *)wMalloc(newLen);
  memcpy(left, string, newLen);
  left[newLen] = '\0';
  wFree(string);
  wPushString(left);
}


x86 assembly (clang, -O0):
<wBasLeft>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <wPopNumber@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1030 <wPopString@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    11c8 <wBasLeft+0x48>
mov    -0x18(%rbp),%rdi
call   1090 <wPushString@plt>
jmp    122c <wBasLeft+0xac>
cmpl   $0x1,-0x4(%rbp)
jge    11ec <wBasLeft+0x6c>
mov    -0x18(%rbp),%rdi
call   10a0 <wFree@plt>
lea    0xe1e(%rip),%rdi
call   1070 <wPushStringCopy@plt>
jmp    122c <wBasLeft+0xac>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <wMalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   10a0 <wFree@plt>
mov    -0x20(%rbp),%rdi
call   1090 <wPushString@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wBasLeft>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <wPopNumber@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <wPopString@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
cmp    %ebx,%eax
jle    11d5 <wBasLeft+0x55>
test   %ebx,%ebx
jle    11e2 <wBasLeft+0x62>
mov    %ebx,%edi
call   1080 <wMalloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <memcpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r14,%rdi
call   10a0 <wFree@plt>
mov    %r15,%rdi
jmp    11d8 <wBasLeft+0x58>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1090 <wPushString@plt>
mov    %r14,%rdi
call   10a0 <wFree@plt>
lea    0xe0f(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <wPushStringCopy@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define void @wBasLeft() {
%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 = sub nsw i32 %12, 1
%14 = icmp sgt i32 %11, %13
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = load i8*, i8** %4
%17 = call i32 @wPushString(i8* %16)
br label %42
18: ; preds = %0
%19 = load i32, i32* %1
%20 = icmp slt i32 %19, 1
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i8*, i8** %4
%23 = call i32 @wFree(i8* %22)
%24 = call i32 @wPushStringCopy(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %42
25: ; preds = %18
%26 = load i32, i32* %1
store i32 %26, i32* %3
%27 = load i32, i32* %3
%28 = call i64 @wMalloc(i32 %27)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %5
%30 = load i8*, i8** %5
%31 = load i8*, i8** %4
%32 = load i32, i32* %3
%33 = call i32 @memcpy(i8* %30, i8* %31, i32 %32)
%34 = load i8*, i8** %5
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %4
%39 = call i32 @wFree(i8* %38)
%40 = load i8*, i8** %5
%41 = call i32 @wPushString(i8* %40)
br label %42
42: ; preds = %25, %21, %15
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define void @wBasLeft() {
%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 %22
8: ; preds = %0
%9 = icmp slt i32 %2, 1
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = tail call i32 @wFree(i8* %3)
%12 = tail call i32 @wPushStringCopy(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %22
13: ; preds = %8
%14 = tail call i64 @wMalloc(i32 %2)
%15 = inttoptr i64 %14 to i8*
%16 = tail call i32 @memcpy(i8* %15, i8* %3, i32 %2)
%17 = shl i64 %1, 32
%18 = ashr exact i64 %17, 32
%19 = getelementptr inbounds i8, i8* %15, i64 %18
store i8 0, i8* %19
%20 = tail call i32 @wFree(i8* %3)
%21 = tail call i32 @wPushString(i8* %15)
br label %22
22: ; preds = %13, %10, %6
ret void
}