#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 */
struct udev {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ strcspn(char const *, char *);
scalar_t__ strncmp(char const *, char *, int);
char *strstr(char const *, char *);
size_t devices_delay_later(struct udev *udev, const char *syspath) {
  const char *c;
  if ((c = strstr(syspath, "/sound/card"))) {
    c += 11;
    c += strcspn(c, "/");
    if (strncmp(c, "/controlC", 9) == 0)
      return c - syspath + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<devices_delay_later>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11c6 <devices_delay_later+0x96>
mov    -0x20(%rbp),%rax
add    $0xb,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe97(%rip),%rsi
call   1040 <strcspn@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe79(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11c1 <devices_delay_later+0x91>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11ce <devices_delay_later+0x9e>
jmp    11c6 <devices_delay_later+0x96>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<devices_delay_later>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xec2(%rip),%rsi
mov    %r14,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     1180 <devices_delay_later+0x50>
mov    %rax,%rbx
lea    0xb(%rax),%rdi
lea    0xeb3(%rip),%rsi
call   1040 <strcspn@plt>
cltq
add    %rax,%rbx
add    $0xb,%rbx
lea    0xea0(%rip),%rsi
mov    %rbx,%rdi
mov    $0x9,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1184 <devices_delay_later+0x54>
xor    %ebx,%ebx
jmp    118b <devices_delay_later+0x5b>
sub    %r14,%rbx
add    $0x1,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.udev = type { i32 }
@.str = [12 x i8] c"/sound/card\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [10 x i8] c"/controlC\00"
define i64 @devices_delay_later(%struct.udev* %0, i8* %1) {
%3 = alloca i64
%4 = alloca %struct.udev*
%5 = alloca i8*
%6 = alloca i8*
store %struct.udev* %0, %struct.udev** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i8* @strstr(i8* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %6
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %29
10: ; preds = %2
%11 = load i8*, i8** %6
%12 = getelementptr inbounds i8, i8* %11, i64 11
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = call i32 @strcspn(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = load i8*, i8** %6
%16 = sext i32 %14 to i64
%17 = getelementptr inbounds i8, i8* %15, i64 %16
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = call i64 @strncmp(i8* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 9)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %10
%22 = load i8*, i8** %6
%23 = load i8*, i8** %5
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
%27 = add nsw i64 %26, 1
store i64 %27, i64* %3
br label %30
28: ; preds = %10
br label %29
29: ; preds = %28, %2
store i64 0, i64* %3
br label %30
30: ; preds = %29, %21
%31 = load i64, i64* %3
ret i64 %31
}

LLVM IR (-O2):
%struct.udev = type { i32 }
@.str = [12 x i8] c"/sound/card\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [10 x i8] c"/controlC\00"
define i64 @devices_delay_later(%struct.udev* nocapture readnone %0, i8* %1) {
%3 = tail call i8* @strstr(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 11
%7 = tail call i32 @strcspn(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = tail call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %5
%13 = ptrtoint i8* %9 to i64
%14 = ptrtoint i8* %1 to i64
%15 = sub i64 1, %14
%16 = add i64 %15, %13
br label %17
17: ; preds = %2, %5, %12
%18 = phi i64 [ %16, %12 ], [ 0, %5 ], [ 0, %2 ]
ret i64 %18
}