#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*/ printf(char *, ...);
char *strcasestr(char *, char *);
size_t strcspn(char *, char *);
size_t strspn(char *, char *);
char *strstr(char *, char *);
void c_string(void) {
  char *haystack = "abcdefghabcdddd";
  char *needle = "cd";
  char *substr = strstr(haystack, needle);
  printf("substr=%s \n", substr);
  substr = strcasestr("abcdedcdddddd", "CD");
  printf("substr=%s \n", substr);
  size_t len = strspn("cdefghhhh111", "cdefg");
  printf("len=%lu\n", len);
  len = strcspn("abcdefgh", "cde");
  printf("len=%lu\n", len);
}


x86 assembly (clang, -O0):
<c_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xea6(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe87(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <strcasestr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6f(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1040 <strspn@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe62(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1050 <strcspn@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_string>:
push   %rbx
lea    0xee8(%rip),%rbx
lea    0xed3(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xedc(%rip),%rdi
lea    0xee3(%rip),%rsi
call   1040 <strcasestr@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xecd(%rip),%rbx
mov    $0x5,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x2,%esi
mov    %rbx,%rdi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"abcdefghabcdddd\00"
@.str.1 = [3 x i8] c"cd\00"
@.str.2 = [12 x i8] c"substr=%s \0A\00"
@.str.3 = [14 x i8] c"abcdedcdddddd\00"
@.str.4 = [3 x i8] c"CD\00"
@.str.5 = [13 x i8] c"cdefghhhh111\00"
@.str.6 = [6 x i8] c"cdefg\00"
@.str.7 = [9 x i8] c"len=%lu\0A\00"
@.str.8 = [9 x i8] c"abcdefgh\00"
@.str.9 = [4 x i8] c"cde\00"
define void @c_string() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %1
%6 = load i8*, i8** %2
%7 = call i8* @strstr(i8* %5, i8* %6)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = call i8* @strcasestr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = call i64 @strspn(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
store i64 %13, i64* %4
%14 = load i64, i64* %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i64 %14)
%16 = call i64 @strcspn(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
store i64 %16, i64* %4
%17 = load i64, i64* %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i64 %17)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"abcdefghabcdddd\00"
@.str.2 = [12 x i8] c"substr=%s \0A\00"
@.str.3 = [14 x i8] c"abcdedcdddddd\00"
@.str.4 = [3 x i8] c"CD\00"
@.str.7 = [9 x i8] c"len=%lu\0A\00"
define void @c_string() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 2))
%2 = tail call i8* @strcasestr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i64 5)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i64 2)
ret void
}