#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*/ strcspn(char *, char const *);
int /*<<< orphan*/ strspn(char *, char const *);
char *sword(char *s, const char *delim, int n) {
  if (s == NULL)
    return NULL;
  s += strspn(s, delim);
  int i;
  for (i = 0; i < n; i++) {
    s += strcspn(s, delim);
    s += strspn(s, delim);
  }
  return s;
}


x86 assembly (clang, -O0):
<sword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114b <sword+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    11cb <sword+0xab>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strspn@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c3 <sword+0xa3>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcspn@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strspn@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116f <sword+0x4f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sword>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     117a <sword+0x5a>
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strspn@plt>
movslq %eax,%rbx
add    %r15,%rbx
test   %r12d,%r12d
jle    117c <sword+0x5c>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcspn@plt>
movslq %eax,%rbp
add    %rbx,%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   1030 <strspn@plt>
movslq %eax,%rbx
add    %rbp,%rbx
add    $0xffffffff,%r12d
jne    1150 <sword+0x30>
jmp    117c <sword+0x5c>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @sword(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %3
store i8* null, i8** %4
br label %41
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i8*, i8** %6
%15 = call i32 @strspn(i8* %13, i8* %14)
%16 = load i8*, i8** %5
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds i8, i8* %16, i64 %17
store i8* %18, i8** %5
store i32 0, i32* %8
br label %19
19: ; preds = %36, %12
%20 = load i32, i32* %8
%21 = load i32, i32* %7
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %39
23: ; preds = %19
%24 = load i8*, i8** %5
%25 = load i8*, i8** %6
%26 = call i32 @strcspn(i8* %24, i8* %25)
%27 = load i8*, i8** %5
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8* %29, i8** %5
%30 = load i8*, i8** %5
%31 = load i8*, i8** %6
%32 = call i32 @strspn(i8* %30, i8* %31)
%33 = load i8*, i8** %5
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8* %35, i8** %5
br label %36
36: ; preds = %23
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %19
39: ; preds = %19
%40 = load i8*, i8** %5
store i8* %40, i8** %4
br label %41
41: ; preds = %39, %11
%42 = load i8*, i8** %4
ret i8* %42
}

LLVM IR (-O2):
define i8* @sword(i8* %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %21, label %5
5: ; preds = %3
%6 = tail call i32 @strspn(i8* %0, i8* %1)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %21
10: ; preds = %5, %10
%11 = phi i32 [ %19, %10 ], [ 0, %5 ]
%12 = phi i8* [ %18, %10 ], [ %8, %5 ]
%13 = tail call i32 @strcspn(i8* %12, i8* %1)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = tail call i32 @strspn(i8* %15, i8* %1)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = add nuw nsw i32 %11, 1
%20 = icmp eq i32 %19, %2
br i1 %20, label %21, label %10
21: ; preds = %10, %5, %3
%22 = phi i8* [ null, %3 ], [ %8, %5 ], [ %18, %10 ]
ret i8* %22
}