#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 */
typedef scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long);
size_t strlen(char *);
char *strstr(char *, char *);
int find_num(char *haystack, uint32_t needle) {
  char *haystack_end = haystack + strlen(haystack);
  char *haystack_start = haystack;
  char needle_str[128];
  snprintf(needle_str, sizeof needle_str, "%lu", (unsigned long)needle);
  size_t needle_len = strlen(needle_str);
  while (1) {
    char *found = strstr(haystack, needle_str);
    char *found_end = found + needle_len;
    if (!found || found_end > haystack_end)
      return 0;
    if ((found == haystack_start || *(found - 1) == ',') &&
        (*found_end == '\0' || *found_end == ','))
      return 1;
    haystack = found + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<find_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0xd0(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0xd0(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0xb0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x80,%esi
lea    0xe79(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0xb0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0xb8(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0xc0(%rbp)
mov    -0xc0(%rbp),%rax
add    -0xb8(%rbp),%rax
mov    %rax,-0xc8(%rbp)
cmpq   $0x0,-0xc0(%rbp)
je     11ea <find_num+0xba>
mov    -0xc8(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    11f6 <find_num+0xc6>
movl   $0x0,-0x4(%rbp)
jmp    1261 <find_num+0x131>
mov    -0xc0(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     121b <find_num+0xeb>
mov    -0xc0(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2c,%eax
jne    124d <find_num+0x11d>
mov    -0xc8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1241 <find_num+0x111>
mov    -0xc8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
jne    124d <find_num+0x11d>
movl   $0x1,-0x4(%rbp)
jmp    1261 <find_num+0x131>
mov    -0xc0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    119f <find_num+0x6f>
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_num>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r14
lea    0xead(%rip),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x80,%esi
mov    %r15,%rcx
call   1040 <snprintf@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     11cb <find_num+0x9b>
add    %rbx,%r14
lea    (%rax,%r15,1),%rcx
cmp    %r14,%rcx
ja     11cb <find_num+0x9b>
mov    %rsp,%r12
cmp    %rbx,%rax
je     119b <find_num+0x6b>
cmpb   $0x2c,-0x1(%rax)
jne    11ac <find_num+0x7c>
movzbl (%rcx),%edx
mov    $0x1,%ecx
test   %dl,%dl
je     11cd <find_num+0x9d>
cmp    $0x2c,%dl
je     11cd <find_num+0x9d>
add    $0x1,%rax
mov    %rax,%rdi
mov    %r12,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     11cb <find_num+0x9b>
mov    %rax,%rcx
add    %r15,%rcx
cmp    %r14,%rcx
jbe    1190 <find_num+0x60>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lu\00"
define i32 @find_num(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [128 x i8]
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
%12 = load i8*, i8** %4
%13 = load i8*, i8** %4
%14 = call i64 @strlen(i8* %13)
%15 = getelementptr inbounds i8, i8* %12, i64 %14
store i8* %15, i8** %6
%16 = load i8*, i8** %4
store i8* %16, i8** %7
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%18 = load i64, i64* %5
%19 = call i32 @snprintf(i8* %17, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %18)
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%21 = call i64 @strlen(i8* %20)
store i64 %21, i64* %9
br label %22
22: ; preds = %2, %57
%23 = load i8*, i8** %4
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%25 = call i8* @strstr(i8* %23, i8* %24)
store i8* %25, i8** %10
%26 = load i8*, i8** %10
%27 = load i64, i64* %9
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8* %28, i8** %11
%29 = load i8*, i8** %10
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %35
31: ; preds = %22
%32 = load i8*, i8** %11
%33 = load i8*, i8** %6
%34 = icmp ugt i8* %32, %33
br i1 %34, label %35, label %36
35: ; preds = %31, %22
store i32 0, i32* %3
br label %60
36: ; preds = %31
%37 = load i8*, i8** %10
%38 = load i8*, i8** %7
%39 = icmp eq i8* %37, %38
br i1 %39, label %46, label %40
40: ; preds = %36
%41 = load i8*, i8** %10
%42 = getelementptr inbounds i8, i8* %41, i64 -1
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 44
br i1 %45, label %46, label %57
46: ; preds = %40, %36
%47 = load i8*, i8** %11
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 0
br i1 %50, label %56, label %51
51: ; preds = %46
%52 = load i8*, i8** %11
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 44
br i1 %55, label %56, label %57
56: ; preds = %51, %46
store i32 1, i32* %3
br label %60
57: ; preds = %51, %40
%58 = load i8*, i8** %10
%59 = getelementptr inbounds i8, i8* %58, i64 1
store i8* %59, i8** %4
br label %22
60: ; preds = %56, %35
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lu\00"
define i32 @find_num(i8* %0, i64 %1) {
%3 = alloca [128 x i8]
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = call i32 @snprintf(i8* %6, i32 128, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %1)
%8 = call i64 @strlen(i8* %6)
%9 = call i8* @strstr(i8* dereferenceable(1) %0, i8* %6)
%10 = getelementptr inbounds i8, i8* %9, i64 %8
%11 = icmp eq i8* %9, null
%12 = icmp ugt i8* %10, %5
%13 = select i1 %11, i1 true, i1 %12
br i1 %13, label %31, label %14
14: ; preds = %2, %24
%15 = phi i8* [ %27, %24 ], [ %10, %2 ]
%16 = phi i8* [ %26, %24 ], [ %9, %2 ]
%17 = icmp eq i8* %16, %0
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = getelementptr inbounds i8, i8* %16, i64 -1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 44
br i1 %21, label %22, label %24
22: ; preds = %18, %14
%23 = load i8, i8* %15
switch i8 %23, label %24 [
i8 0, label %31
i8 44, label %31
]
24: ; preds = %18, %22
%25 = getelementptr inbounds i8, i8* %16, i64 1
%26 = call i8* @strstr(i8* dereferenceable(1) %25, i8* %6)
%27 = getelementptr inbounds i8, i8* %26, i64 %8
%28 = icmp eq i8* %26, null
%29 = icmp ugt i8* %27, %5
%30 = select i1 %28, i1 true, i1 %29
br i1 %30, label %31, label %14
31: ; preds = %22, %22, %24, %2
%32 = phi i32 [ 0, %2 ], [ 0, %24 ], [ 1, %22 ], [ 1, %22 ]
ret i32 %32
}