#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 strlen(char *);
int /*<<< orphan*/ wFree(char *);
scalar_t__ wMalloc(int);
scalar_t__ wPopNumber();
char *wPopString();
int /*<<< orphan*/ wPushString(char *);
void wBasMid() {
  int i, j, n, len;
  char *string, *buffer;
  n = (int)wPopNumber();
  i = (int)wPopNumber();
  string = wPopString();
  len = strlen(string);
  if (i < 1 || i > len) {
    wPushString("");
    wFree(string);
    return;
  }
  buffer = (char *)wMalloc(len + 2);
  for (j = 0; j < n; j++) {
    if (string[i + j - 1] == '\0') {
      break;
    }
    buffer[j] = string[i + j - 1];
  }
  buffer[j] = '\0';
  wPushString(buffer);
  wFree(string);
}


x86 assembly (clang, -O0):
<wBasMid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <wPopNumber@plt>
mov    %eax,-0xc(%rbp)
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,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
jl     11a9 <wBasMid+0x49>
mov    -0x4(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    11c3 <wBasMid+0x63>
lea    0xe50(%rip),%rdi
call   1070 <wPushString@plt>
mov    -0x18(%rbp),%rdi
call   1080 <wFree@plt>
jmp    1251 <wBasMid+0xf1>
mov    -0x10(%rbp),%edi
add    $0x2,%edi
call   1060 <wMalloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1233 <wBasMid+0xd3>
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
add    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1207 <wBasMid+0xa7>
jmp    1233 <wBasMid+0xd3>
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
add    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d9 <wBasMid+0x79>
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1070 <wPushString@plt>
mov    -0x18(%rbp),%rdi
call   1080 <wFree@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wBasMid>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <wPopNumber@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <wPopNumber@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1030 <wPopString@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0xe6b(%rip),%rdi
test   %r15d,%r15d
jle    120c <wBasMid+0xac>
cmp    %r15d,%eax
jl     120c <wBasMid+0xac>
add    $0x2,%eax
mov    %eax,%edi
call   1060 <wMalloc@plt>
mov    %rax,%rdi
test   %r14d,%r14d
jle    1204 <wBasMid+0xa4>
mov    %r14d,%ecx
shl    $0x20,%r15
movabs $0xffffffff00000000,%rsi
ff ff ff
add    %r15,%rsi
xor    %eax,%eax
movabs $0x100000000,%r8
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rsi,%rdx
sar    $0x20,%rdx
movzbl (%r12,%rdx,1),%ebx
test   %bl,%bl
je     1206 <wBasMid+0xa6>
mov    %bl,(%rdi,%rax,1)
add    $0x1,%rax
add    %r8,%rsi
cmp    %rax,%rcx
jne    11e0 <wBasMid+0x80>
mov    %r14,%rax
jmp    1206 <wBasMid+0xa6>
xor    %eax,%eax
mov    %eax,%eax
movb   $0x0,(%rdi,%rax,1)
call   1070 <wPushString@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1080 <wFree@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define void @wBasMid() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = call i64 (...) @wPopNumber()
%8 = trunc i64 %7 to i32
store i32 %8, i32* %3
%9 = call i64 (...) @wPopNumber()
%10 = trunc i64 %9 to i32
store i32 %10, i32* %1
%11 = call i8* (...) @wPopString()
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %4
%14 = load i32, i32* %1
%15 = icmp slt i32 %14, 1
br i1 %15, label %20, label %16
16: ; preds = %0
%17 = load i32, i32* %1
%18 = load i32, i32* %4
%19 = icmp sgt i32 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %16, %0
%21 = call i32 @wPushString(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%22 = load i8*, i8** %5
%23 = call i32 @wFree(i8* %22)
br label %70
24: ; preds = %16
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 2
%27 = call i64 @wMalloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %6
store i32 0, i32* %2
br label %29
29: ; preds = %58, %24
%30 = load i32, i32* %2
%31 = load i32, i32* %3
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %61
33: ; preds = %29
%34 = load i8*, i8** %5
%35 = load i32, i32* %1
%36 = load i32, i32* %2
%37 = add nsw i32 %35, %36
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %34, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %33
br label %61
45: ; preds = %33
%46 = load i8*, i8** %5
%47 = load i32, i32* %1
%48 = load i32, i32* %2
%49 = add nsw i32 %47, %48
%50 = sub nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %46, i64 %51
%53 = load i8, i8* %52
%54 = load i8*, i8** %6
%55 = load i32, i32* %2
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 %53, i8* %57
br label %58
58: ; preds = %45
%59 = load i32, i32* %2
%60 = add nsw i32 %59, 1
store i32 %60, i32* %2
br label %29
61: ; preds = %44, %29
%62 = load i8*, i8** %6
%63 = load i32, i32* %2
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
store i8 0, i8* %65
%66 = load i8*, i8** %6
%67 = call i32 @wPushString(i8* %66)
%68 = load i8*, i8** %5
%69 = call i32 @wFree(i8* %68)
br label %70
70: ; preds = %61, %20
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define void @wBasMid() {
%1 = tail call i64 (...) @wPopNumber()
%2 = tail call i64 (...) @wPopNumber()
%3 = trunc i64 %2 to i32
%4 = tail call i8* (...) @wPopString()
%5 = tail call i32 @strlen(i8* %4)
%6 = icmp slt i32 %3, 1
%7 = icmp slt i32 %5, %3
%8 = select i1 %6, i1 true, i1 %7
br i1 %8, label %34, label %9
9: ; preds = %0
%10 = trunc i64 %1 to i32
%11 = add nsw i32 %5, 2
%12 = tail call i64 @wMalloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = add i64 %2, 4294967295
%15 = icmp sgt i32 %10, 0
br i1 %15, label %16, label %30
16: ; preds = %9
%17 = and i64 %1, 4294967295
br label %18
18: ; preds = %16, %26
%19 = phi i64 [ 0, %16 ], [ %28, %26 ]
%20 = add i64 %14, %19
%21 = shl i64 %20, 32
%22 = ashr exact i64 %21, 32
%23 = getelementptr inbounds i8, i8* %4, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %18
%27 = getelementptr inbounds i8, i8* %13, i64 %19
store i8 %24, i8* %27
%28 = add nuw nsw i64 %19, 1
%29 = icmp eq i64 %28, %17
br i1 %29, label %30, label %18
30: ; preds = %26, %18, %9
%31 = phi i64 [ 0, %9 ], [ %19, %18 ], [ %1, %26 ]
%32 = and i64 %31, 4294967295
%33 = getelementptr inbounds i8, i8* %13, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %0, %30
%35 = phi i8* [ %13, %30 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %0 ]
%36 = tail call i32 @wPushString(i8* %35)
%37 = tail call i32 @wFree(i8* %4)
ret void
}