#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 const *, size_t);
scalar_t__ mu__malloc(char *, int, size_t);
size_t strlen(char const *);
char *astrmid(const char *src, size_t offset, size_t count) {
  char *midString = NULL;
  size_t actualCount;
  if (offset >= strlen(src)) {
    return NULL;
  } else {
    if ((count == 0) || (offset + count > strlen(src))) {
      actualCount = strlen(src) - offset;
    } else {
      actualCount = count;
    }
    midString = (char *)mu__malloc(
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/kaiaie/bile/refs/heads/master/src/astring.c",
        108, (actualCount + 1) * sizeof(char));
    memcpy(midString, &src[offset], actualCount);
    midString[actualCount] = '\0';
  }
  return midString;
}


x86 assembly (clang, -O0):
<astrmid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jb     117a <astrmid+0x4a>
movq   $0x0,-0x8(%rbp)
jmp    1212 <astrmid+0xe2>
cmpq   $0x0,-0x20(%rbp)
je     11aa <astrmid+0x7a>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jbe    11c0 <astrmid+0x90>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11c8 <astrmid+0x98>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdx
add    $0x1,%rdx
shl    $0x0,%rdx
lea    0xe25(%rip),%rdi
mov    $0x6c,%esi
call   1050 <mu__malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<astrmid>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%rcx
sub    %r14,%rcx
jbe    1193 <astrmid+0x63>
lea    (%r12,%r14,1),%rdx
cmp    %rax,%rdx
mov    %r12,%rbx
cmova  %rcx,%rbx
test   %r12,%r12
cmove  %rcx,%rbx
lea    0x1(%rbx),%rdx
lea    0xe92(%rip),%rdi
mov    $0x6c,%esi
call   1050 <mu__malloc@plt>
mov    %rax,%r12
add    %r14,%r15
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
movb   $0x0,(%r12,%rbx,1)
jmp    1196 <astrmid+0x66>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kaiaie/bile/refs/heads/master/src/astring.c\00"
define i8* @astrmid(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i8* null, i8** %8
%10 = load i64, i64* %6
%11 = load i8*, i8** %5
%12 = call i64 @strlen(i8* %11)
%13 = icmp uge i64 %10, %12
br i1 %13, label %14, label %15
14: ; preds = %3
store i8* null, i8** %4
br label %49
15: ; preds = %3
%16 = load i64, i64* %7
%17 = icmp eq i64 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = load i64, i64* %6
%20 = load i64, i64* %7
%21 = add i64 %19, %20
%22 = load i8*, i8** %5
%23 = call i64 @strlen(i8* %22)
%24 = icmp ugt i64 %21, %23
br i1 %24, label %25, label %30
25: ; preds = %18, %15
%26 = load i8*, i8** %5
%27 = call i64 @strlen(i8* %26)
%28 = load i64, i64* %6
%29 = sub i64 %27, %28
store i64 %29, i64* %9
br label %32
30: ; preds = %18
%31 = load i64, i64* %7
store i64 %31, i64* %9
br label %32
32: ; preds = %30, %25
%33 = load i64, i64* %9
%34 = add i64 %33, 1
%35 = mul i64 %34, 1
%36 = call i64 @mu__malloc(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 108, i64 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %8
%38 = load i8*, i8** %8
%39 = load i8*, i8** %5
%40 = load i64, i64* %6
%41 = getelementptr inbounds i8, i8* %39, i64 %40
%42 = load i64, i64* %9
%43 = call i32 @memcpy(i8* %38, i8* %41, i64 %42)
%44 = load i8*, i8** %8
%45 = load i64, i64* %9
%46 = getelementptr inbounds i8, i8* %44, i64 %45
store i8 0, i8* %46
br label %47
47: ; preds = %32
%48 = load i8*, i8** %8
store i8* %48, i8** %4
br label %49
49: ; preds = %47, %14
%50 = load i8*, i8** %4
ret i8* %50
}

LLVM IR (-O2):
@.str = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kaiaie/bile/refs/heads/master/src/astring.c\00"
define i8* @astrmid(i8* %0, i64 %1, i64 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = icmp ugt i64 %4, %1
br i1 %5, label %6, label %19
6: ; preds = %3
%7 = icmp eq i64 %2, 0
%8 = add i64 %2, %1
%9 = icmp ugt i64 %8, %4
%10 = select i1 %7, i1 true, i1 %9
%11 = sub i64 %4, %1
%12 = select i1 %10, i64 %11, i64 %2
%13 = add i64 %12, 1
%14 = tail call i64 @mu__malloc(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 108, i64 %13)
%15 = inttoptr i64 %14 to i8*
%16 = getelementptr inbounds i8, i8* %0, i64 %1
%17 = tail call i32 @memcpy(i8* %15, i8* %16, i64 %12)
%18 = getelementptr inbounds i8, i8* %15, i64 %12
store i8 0, i8* %18
br label %19
19: ; preds = %3, %6
%20 = phi i8* [ %15, %6 ], [ null, %3 ]
ret i8* %20
}