#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 strlen(char const *);
char *strstr(char const *, char const *);
char *str_list_find(const char *str_list, const char *str) {
  char *before;
  char *after;
  char *ch;
  ch = strstr(str_list, str);
  if (ch == NULL)
    return NULL;
  if (ch != str_list) {
    before = ch - 1;
    if (*before != ',')
      return NULL;
  }
  after = ch + strlen(str);
  if (*after != ',' && *after != '\0')
    return NULL;
  return ch;
}


x86 assembly (clang, -O0):
<str_list_find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1159 <str_list_find+0x39>
movq   $0x0,-0x8(%rbp)
jmp    11eb <str_list_find+0xcb>
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1195 <str_list_find+0x75>
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
je     1190 <str_list_find+0x70>
movq   $0x0,-0x8(%rbp)
jmp    11eb <str_list_find+0xcb>
jmp    1195 <str_list_find+0x75>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
je     11e3 <str_list_find+0xc3>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e3 <str_list_find+0xc3>
movq   $0x0,-0x8(%rbp)
jmp    11eb <str_list_find+0xcb>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_list_find>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strstr@plt>
test   %rax,%rax
je     1158 <str_list_find+0x38>
mov    %rax,%rbx
cmp    %r15,%rax
je     1143 <str_list_find+0x23>
cmpb   $0x2c,-0x1(%rbx)
jne    1158 <str_list_find+0x38>
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
mov    (%rbx,%rax,1),%al
cmp    $0x2c,%al
je     115a <str_list_find+0x3a>
test   %al,%al
je     115a <str_list_find+0x3a>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @str_list_find(i8* %0, i8* %1) {
%3 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = icmp eq i8* %3, %0
br i1 %6, label %11, label %7
7: ; preds = %5
%8 = getelementptr inbounds i8, i8* %3, i64 -1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 44
br i1 %10, label %11, label %17
11: ; preds = %7, %5
%12 = tail call i32 @strlen(i8* %1)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %3, i64 %13
%15 = load i8, i8* %14
switch i8 %15, label %17 [
i8 44, label %16
i8 0, label %16
]
16: ; preds = %11, %11
br label %17
17: ; preds = %11, %7, %2, %16
%18 = phi i8* [ %3, %16 ], [ null, %2 ], [ null, %7 ], [ null, %11 ]
ret i8* %18
}