#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 */
scalar_t__ checkPointerError(int /*<<< orphan*/, char *, char *, int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ malloc(int);
char *strdup(char *);
int strlen(char *);
char *strdupdel(char *src, char delimiter) {
  char *id = src;
  char *val, *val_src;
  char *result = NULL;
  if (id) {
    while (*(id++) != delimiter)
      ;
    val = val_src = (char *)checkPointerError(
        malloc(sizeof(char) * (strlen(id) + 1)), "Can't allocate memory",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/r78v10a07/gTools/refs/heads/master/gTools/"
        "src/bstring.c",
        69, -1);
    while (*id != delimiter && *id != '\0' && *id != '\n' && *id != '\r') {
      *(val++) = *(id++);
    }
    *val = '\0';
    result = strdup(val_src);
    free(val_src);
  }
  return result;
}


x86 assembly (clang, -O0):
<strdupdel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     128c <strdupdel+0x13c>
jmp    1182 <strdupdel+0x32>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
je     11a5 <strdupdel+0x55>
jmp    1182 <strdupdel+0x32>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %eax,%edi
lea    0xe39(%rip),%rsi
lea    0xe48(%rip),%rdx
mov    $0x45,%ecx
mov    $0xffffffff,%r8d
call   1060 <checkPointerError@plt>
mov    %rax,-0x28(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
movsbl -0x9(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x31(%rbp)
je     1238 <strdupdel+0xe8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
je     1238 <strdupdel+0xe8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x31(%rbp)
je     1238 <strdupdel+0xe8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1248 <strdupdel+0xf8>
jmp    126f <strdupdel+0x11f>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    11e6 <strdupdel+0x96>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strdupdel>:
test   %rdi,%rdi
je     1213 <strdupdel+0xc3>
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rax
add    $0x1,%rbx
cmp    %bpl,(%rax)
jne    1170 <strdupdel+0x20>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
lea    0xe6d(%rip),%rsi
lea    0xe7c(%rip),%rdx
mov    %eax,%edi
mov    $0x45,%ecx
mov    $0xffffffff,%r8d
call   1060 <checkPointerError@plt>
mov    %rax,%r14
mov    (%rbx),%al
mov    %r14,%rdx
cmp    %bpl,%al
je     11f5 <strdupdel+0xa5>
xor    %ecx,%ecx
mov    $0x2401,%edx
jmp    11e2 <strdupdel+0x92>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %al,(%r14,%rcx,1)
movzbl 0x1(%rbx,%rcx,1),%eax
add    $0x1,%rcx
cmp    %bpl,%al
je     11ef <strdupdel+0x9f>
cmp    $0xd,%al
ja     11d0 <strdupdel+0x80>
movzbl %al,%esi
bt     %rsi,%rdx
jae    11d0 <strdupdel+0x80>
mov    %r14,%rdx
add    %rcx,%rdx
movb   $0x0,(%rdx)
mov    %r14,%rdi
call   1070 <strdup@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Can't allocate memory\00"
@.str.1 = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/r78v10a07/gTools/refs/heads/master/gTools/src/bstring.c\00"
define i8* @strdupdel(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
store i8 %1, i8* %4
%9 = load i8*, i8** %3
store i8* %9, i8** %5
store i8* null, i8** %8
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %68
12: ; preds = %2
br label %13
13: ; preds = %21, %12
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %5
%16 = load i8, i8* %14
%17 = sext i8 %16 to i32
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %17, %19
br i1 %20, label %21, label %22
21: ; preds = %13
br label %13
22: ; preds = %13
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = mul i64 1, %26
%28 = trunc i64 %27 to i32
%29 = call i32 @malloc(i32 %28)
%30 = call i64 @checkPointerError(i32 %29, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str.1, i64 0, i64 0), i32 69, i32 -1)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %7
store i8* %31, i8** %6
br label %32
32: ; preds = %56, %22
%33 = load i8*, i8** %5
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = load i8, i8* %4
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %35, %37
br i1 %38, label %39, label %54
39: ; preds = %32
%40 = load i8*, i8** %5
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %54
44: ; preds = %39
%45 = load i8*, i8** %5
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 10
br i1 %48, label %49, label %54
49: ; preds = %44
%50 = load i8*, i8** %5
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 13
br label %54
54: ; preds = %49, %44, %39, %32
%55 = phi i1 [ false, %44 ], [ false, %39 ], [ false, %32 ], [ %53, %49 ]
br i1 %55, label %56, label %62
56: ; preds = %54
%57 = load i8*, i8** %5
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %5
%59 = load i8, i8* %57
%60 = load i8*, i8** %6
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %6
store i8 %59, i8* %60
br label %32
62: ; preds = %54
%63 = load i8*, i8** %6
store i8 0, i8* %63
%64 = load i8*, i8** %7
%65 = call i8* @strdup(i8* %64)
store i8* %65, i8** %8
%66 = load i8*, i8** %7
%67 = call i32 @free(i8* %66)
br label %68
68: ; preds = %62, %2
%69 = load i8*, i8** %8
ret i8* %69
}

LLVM IR (-O2):
@.str = [22 x i8] c"Can't allocate memory\00"
@.str.1 = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/r78v10a07/gTools/refs/heads/master/gTools/src/bstring.c\00"
define noalias i8* @strdupdel(i8* %0, i8 signext %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %32, label %4
4: ; preds = %2, %4
%5 = phi i8* [ %6, %4 ], [ %0, %2 ]
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = load i8, i8* %5
%8 = icmp eq i8 %7, %1
br i1 %8, label %9, label %4
9: ; preds = %4
%10 = tail call i32 @strlen(i8* %6)
%11 = add nsw i32 %10, 1
%12 = tail call i32 @malloc(i32 %11)
%13 = tail call i64 @checkPointerError(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str.1, i64 0, i64 0), i32 69, i32 -1)
%14 = inttoptr i64 %13 to i8*
%15 = load i8, i8* %6
%16 = freeze i8 %15
%17 = icmp eq i8 %16, %1
br i1 %17, label %28, label %18
18: ; preds = %9, %22
%19 = phi i8 [ %26, %22 ], [ %16, %9 ]
%20 = phi i8* [ %23, %22 ], [ %6, %9 ]
%21 = phi i8* [ %24, %22 ], [ %14, %9 ]
switch i8 %19, label %22 [
i8 13, label %28
i8 10, label %28
i8 0, label %28
]
22: ; preds = %18
%23 = getelementptr inbounds i8, i8* %20, i64 1
%24 = getelementptr inbounds i8, i8* %21, i64 1
store i8 %19, i8* %21
%25 = load i8, i8* %23
%26 = freeze i8 %25
%27 = icmp eq i8 %26, %1
br i1 %27, label %28, label %18
28: ; preds = %22, %18, %18, %18, %9
%29 = phi i8* [ %14, %9 ], [ %21, %18 ], [ %21, %18 ], [ %21, %18 ], [ %24, %22 ]
store i8 0, i8* %29
%30 = tail call i8* @strdup(i8* %14)
%31 = tail call i32 @free(i8* %14)
br label %32
32: ; preds = %28, %2
%33 = phi i8* [ %30, %28 ], [ null, %2 ]
ret i8* %33
}