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


x86 assembly (clang, -O0):
<test_strcut_second>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%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   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1080 <memcpy@plt>
mov    -0x20(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1040 <strchr@plt>
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     120b <test_strcut_second+0x9b>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    $0xffffffff,%edx
call   1090 <strcut@plt>
jmp    121c <test_strcut_second+0xac>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1090 <strcut@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strcut_second>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbp
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <memcpy@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1040 <strchr@plt>
sub    %ebx,%eax
test   %r15d,%r15d
je     11cf <test_strcut_second+0x5f>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0xffffffff,%edx
jmp    11d9 <test_strcut_second+0x69>
add    $0x1,%eax
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1090 <strcut@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <memcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <assert@plt>

LLVM IR (-O0):
define void @test_strcut_second(i8* %0, i8 signext %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %5
store i8 %1, i8* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%11 = load i8*, i8** %5
%12 = call i64 @strlen(i8* %11)
%13 = add nsw i64 %12, 1
%14 = call i8* @calloc(i64 %13, i32 1)
store i8* %14, i8** %9
%15 = load i8*, i8** %9
%16 = load i8*, i8** %5
%17 = load i8*, i8** %5
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %18, 1
%20 = call i32 @memcpy(i8* %15, i8* %16, i64 %19)
%21 = load i8*, i8** %9
%22 = load i8, i8* %6
%23 = call i8* @strchr(i8* %21, i8 signext %22)
%24 = load i8*, i8** %9
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
store i32 %28, i32* %10
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %4
%32 = load i8*, i8** %9
%33 = load i32, i32* %10
%34 = call i32 @strcut(i8* %32, i32 %33, i32 -1)
br label %40
35: ; preds = %4
%36 = load i8*, i8** %9
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 1
%39 = call i32 @strcut(i8* %36, i32 0, i32 %38)
br label %40
40: ; preds = %35, %31
%41 = load i8*, i8** %9
%42 = load i8*, i8** %8
%43 = load i8*, i8** %8
%44 = call i64 @strlen(i8* %43)
%45 = add nsw i64 %44, 1
%46 = call i64 @memcmp(i8* %41, i8* %42, i64 %45)
%47 = icmp eq i64 %46, 0
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
ret void
}

LLVM IR (-O2):
define void @test_strcut_second(i8* %0, i8 signext %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 i8* @strchr(i8* dereferenceable(1) %7, i8 signext %1)
%12 = ptrtoint i8* %11 to i64
%13 = ptrtoint i8* %7 to i64
%14 = sub i64 %12, %13
%15 = trunc i64 %14 to i32
%16 = icmp eq i32 %2, 0
br i1 %16, label %19, label %17
17: ; preds = %4
%18 = tail call i32 @strcut(i8* %7, i32 %15, i32 -1)
br label %22
19: ; preds = %4
%20 = add nsw i32 %15, 1
%21 = tail call i32 @strcut(i8* %7, i32 0, i32 %20)
br label %22
22: ; preds = %19, %17
%23 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%24 = add nsw i64 %23, 1
%25 = tail call i64 @memcmp(i8* %7, i8* %3, i64 %24)
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i32
%28 = tail call i32 @assert(i32 %27)
ret void
}