#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 strcspn(char *, char const *);
char *str_cut(char *str, const char *delim) {
  char *p;
  static char *secret_state;
  p = str ? str : secret_state;
  if (p == NULL) {
    return (NULL);
  }
  secret_state = p + strcspn(p, delim);
  if (*secret_state) {
    *secret_state++ = 0;
  } else {
    secret_state = NULL;
  }
  return (p);
}


x86 assembly (clang, -O0):
<str_cut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1138 <str_cut+0x28>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1143 <str_cut+0x33>
mov    0x2ef1(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1163 <str_cut+0x53>
movq   $0x0,-0x8(%rbp)
jmp    11cb <str_cut+0xbb>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcspn@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,0x2ea5(%rip)
mov    0x2e9e(%rip),%rax
cmpb   $0x0,(%rax)
je     11b8 <str_cut+0xa8>
mov    0x2e8e(%rip),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2e80(%rip)
movb   $0x0,(%rax)
jmp    11c3 <str_cut+0xb3>
movq   $0x0,0x2e6d(%rip)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_cut>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1120 <str_cut+0x10>
mov    0x2f10(%rip),%rbx
test   %rbx,%rbx
je     1153 <str_cut+0x43>
mov    %rbx,%rdi
call   1030 <strcspn@plt>
cltq
cmpb   $0x0,(%rbx,%rax,1)
je     1148 <str_cut+0x38>
add    %rbx,%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x2eed(%rip)
movb   $0x0,(%rax)
jmp    1153 <str_cut+0x43>
movq   $0x0,0x2edd(%rip)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@str_cut.secret_state = internal global i8* null
define i8* @str_cut(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = load i8*, i8** %4
br label %13
11: ; preds = %2
%12 = load i8*, i8** @str_cut.secret_state
br label %13
13: ; preds = %11, %9
%14 = phi i8* [ %10, %9 ], [ %12, %11 ]
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %13
store i8* null, i8** %3
br label %34
18: ; preds = %13
%19 = load i8*, i8** %6
%20 = load i8*, i8** %6
%21 = load i8*, i8** %5
%22 = call i32 @strcspn(i8* %20, i8* %21)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %19, i64 %23
store i8* %24, i8** @str_cut.secret_state
%25 = load i8*, i8** @str_cut.secret_state
%26 = load i8, i8* %25
%27 = icmp ne i8 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %18
%29 = load i8*, i8** @str_cut.secret_state
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** @str_cut.secret_state
store i8 0, i8* %29
br label %32
31: ; preds = %18
store i8* null, i8** @str_cut.secret_state
br label %32
32: ; preds = %31, %28
%33 = load i8*, i8** %6
store i8* %33, i8** %3
br label %34
34: ; preds = %32, %17
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
@str_cut.secret_state = internal unnamed_addr global i8* null
define i8* @str_cut(i8* %0, i8* nocapture %1) {
%3 = icmp eq i8* %0, null
%4 = load i8*, i8** @str_cut.secret_state
%5 = select i1 %3, i8* %4, i8* %0
%6 = icmp eq i8* %5, null
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = tail call i32 @strcspn(i8* %5, i8* %1)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %5, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = getelementptr inbounds i8, i8* %10, i64 1
store i8* %14, i8** @str_cut.secret_state
store i8 0, i8* %10
br label %16
15: ; preds = %7
store i8* null, i8** @str_cut.secret_state
br label %16
16: ; preds = %13, %15, %2
ret i8* %5
}