#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*/ memset(char *, int /*<<< orphan*/, int);
char randchar();
int /*<<< orphan*/ string_contains(char *, int, char *, int);
int string_delim(char *s, int s_n, char *d, int d_n) {
  int i;
  if (d_n < 4)
    return -1;
  memset(d, 0, d_n + 1);
  for (i = 0; i < 3; i++) {
    d[i] = randchar();
  }
  for (; i < d_n; i++) {
    if (!string_contains(s, s_n, d, i)) {
      return i;
    }
    d[i] = randchar();
  }
  return -1;
}


x86 assembly (clang, -O0):
<string_delim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    115c <string_delim+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1201 <string_delim+0xd1>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1030 <memset@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x28(%rbp)
jge    11a0 <string_delim+0x70>
mov    $0x0,%al
call   1040 <randchar@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1174 <string_delim+0x44>
jmp    11a5 <string_delim+0x75>
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11fa <string_delim+0xca>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%ecx
call   1050 <string_contains@plt>
cmp    $0x0,%eax
jne    11d8 <string_delim+0xa8>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1201 <string_delim+0xd1>
mov    $0x0,%al
call   1040 <randchar@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11a5 <string_delim+0x75>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_delim>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%r14d
cmp    $0x4,%ecx
jl     11bc <string_delim+0x8c>
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %rdi,%r13
lea    0x1(%r12),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
xor    %eax,%eax
call   1040 <randchar@plt>
mov    %al,(%rbx)
xor    %eax,%eax
call   1040 <randchar@plt>
mov    %al,0x1(%rbx)
xor    %eax,%eax
call   1040 <randchar@plt>
mov    %al,0x2(%rbx)
mov    %r12d,%r12d
mov    $0x3,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1050 <string_contains@plt>
test   %eax,%eax
je     11b9 <string_delim+0x89>
xor    %eax,%eax
call   1040 <randchar@plt>
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1190 <string_delim+0x60>
jmp    11bc <string_delim+0x8c>
mov    %ebp,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @string_delim(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load i32, i32* %9
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %14
13: ; preds = %4
store i32 -1, i32* %5
br label %55
14: ; preds = %4
%15 = load i8*, i8** %8
%16 = load i32, i32* %9
%17 = add nsw i32 %16, 1
%18 = call i32 @memset(i8* %15, i32 0, i32 %17)
store i32 0, i32* %10
br label %19
19: ; preds = %28, %14
%20 = load i32, i32* %10
%21 = icmp slt i32 %20, 3
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = call signext i8 (...) @randchar()
%24 = load i8*, i8** %8
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 %23, i8* %27
br label %28
28: ; preds = %22
%29 = load i32, i32* %10
%30 = add nsw i32 %29, 1
store i32 %30, i32* %10
br label %19
31: ; preds = %19
br label %32
32: ; preds = %51, %31
%33 = load i32, i32* %10
%34 = load i32, i32* %9
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %54
36: ; preds = %32
%37 = load i8*, i8** %6
%38 = load i32, i32* %7
%39 = load i8*, i8** %8
%40 = load i32, i32* %10
%41 = call i32 @string_contains(i8* %37, i32 %38, i8* %39, i32 %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %36
%44 = load i32, i32* %10
store i32 %44, i32* %5
br label %55
45: ; preds = %36
%46 = call signext i8 (...) @randchar()
%47 = load i8*, i8** %8
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 %46, i8* %50
br label %51
51: ; preds = %45
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
store i32 %53, i32* %10
br label %32
54: ; preds = %32
store i32 -1, i32* %5
br label %55
55: ; preds = %54, %43, %13
%56 = load i32, i32* %5
ret i32 %56
}

LLVM IR (-O2):
define i32 @string_delim(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp slt i32 %3, 4
br i1 %5, label %27, label %6
6: ; preds = %4
%7 = add nuw nsw i32 %3, 1
%8 = tail call i32 @memset(i8* %2, i32 0, i32 %7)
%9 = tail call signext i8 (...) @randchar()
store i8 %9, i8* %2
%10 = tail call signext i8 (...) @randchar()
%11 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %10, i8* %11
%12 = tail call signext i8 (...) @randchar()
%13 = getelementptr inbounds i8, i8* %2, i64 2
store i8 %12, i8* %13
%14 = zext i32 %3 to i64
br label %15
15: ; preds = %6, %20
%16 = phi i64 [ 3, %6 ], [ %23, %20 ]
%17 = trunc i64 %16 to i32
%18 = tail call i32 @string_contains(i8* %0, i32 %1, i8* %2, i32 %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %15
%21 = tail call signext i8 (...) @randchar()
%22 = getelementptr inbounds i8, i8* %2, i64 %16
store i8 %21, i8* %22
%23 = add nuw nsw i64 %16, 1
%24 = icmp eq i64 %23, %14
br i1 %24, label %27, label %15
25: ; preds = %15
%26 = trunc i64 %16 to i32
br label %27
27: ; preds = %20, %25, %4
%28 = phi i32 [ -1, %4 ], [ %26, %25 ], [ -1, %20 ]
ret i32 %28
}