#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*/ assert(int);
char *calloc(scalar_t__, int);
scalar_t__ memcmp(char *, char *, scalar_t__);
int /*<<< orphan*/ memcpy(char *, char *, scalar_t__);
int /*<<< orphan*/ strcut(char *, int, int);
scalar_t__ strlen(char *);
void test_strcut_first(char *in, int offset, int len, char *expected) {
  char *p;
  p = calloc(strlen(in) + 1, sizeof(*in));
  memcpy(p, in, strlen(in) + 1);
  strcut(p, offset, len);
  assert(memcmp(p, expected, strlen(expected) + 1) == 0);
}


x86 assembly (clang, -O0):
<test_strcut_first>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1070 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1080 <strcut@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strcut_first>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r12
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbp
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <memcpy@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1080 <strcut@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <memcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <assert@plt>

LLVM IR (-O0):
define void @test_strcut_first(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %11, 1
%13 = call i8* @calloc(i64 %12, i32 1)
store i8* %13, i8** %9
%14 = load i8*, i8** %9
%15 = load i8*, i8** %5
%16 = load i8*, i8** %5
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %17, 1
%19 = call i32 @memcpy(i8* %14, i8* %15, i64 %18)
%20 = load i8*, i8** %9
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = call i32 @strcut(i8* %20, i32 %21, i32 %22)
%24 = load i8*, i8** %9
%25 = load i8*, i8** %8
%26 = load i8*, i8** %8
%27 = call i64 @strlen(i8* %26)
%28 = add nsw i64 %27, 1
%29 = call i64 @memcmp(i8* %24, i8* %25, i64 %28)
%30 = icmp eq i64 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
ret void
}

LLVM IR (-O2):
define void @test_strcut_first(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = add nsw i64 %5, 1
%7 = tail call i8* @calloc(i64 %6, i32 1)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%9 = add nsw i64 %8, 1
%10 = tail call i32 @memcpy(i8* %7, i8* %0, i64 %9)
%11 = tail call i32 @strcut(i8* %7, i32 %1, i32 %2)
%12 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%13 = add nsw i64 %12, 1
%14 = tail call i64 @memcmp(i8* %7, i8* %3, i64 %13)
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
ret void
}