#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 */
char *strstr(char *, char *);
int lsusb_test(char *str) {
  int device_count = 0;
  char *p;
  for (p = str; (p = strstr(p, "Device")) != NULL; p++)
    device_count++;
  if (device_count == 1)
    return 0;
  return -1;
}


x86 assembly (clang, -O0):
<lsusb_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xeca(%rip),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1163 <lsusb_test+0x53>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112b <lsusb_test+0x1b>
cmpl   $0x1,-0x14(%rbp)
jne    1179 <lsusb_test+0x69>
movl   $0x0,-0x4(%rbp)
jmp    1180 <lsusb_test+0x70>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lsusb_test>:
push   %rbp
push   %rbx
push   %rax
lea    0xee6(%rip),%rsi
call   1030 <strstr@plt>
test   %rax,%rax
je     114d <lsusb_test+0x3d>
mov    $0x1,%ebp
lea    0xed0(%rip),%rbx
add    $0x1,%rax
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strstr@plt>
add    $0xffffffff,%ebp
test   %rax,%rax
jne    1130 <lsusb_test+0x20>
neg    %ebp
sbb    %eax,%eax
jmp    1152 <lsusb_test+0x42>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"Device\00"
define i32 @lsusb_test(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %4
%6 = load i8*, i8** %3
store i8* %6, i8** %5
br label %7
7: ; preds = %14, %1
%8 = load i8*, i8** %5
%9 = call i8* @strstr(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
store i32 %13, i32* %4
br label %14
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %5
br label %7
17: ; preds = %7
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 0, i32* %2
br label %22
21: ; preds = %17
store i32 -1, i32* %2
br label %22
22: ; preds = %21, %20
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [7 x i8] c"Device\00"
define i32 @lsusb_test(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %14, label %4
4: ; preds = %1, %4
%5 = phi i8* [ %9, %4 ], [ %2, %1 ]
%6 = phi i32 [ %7, %4 ], [ 0, %1 ]
%7 = add nuw nsw i32 %6, 1
%8 = getelementptr inbounds i8, i8* %5, i64 1
%9 = tail call i8* @strstr(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %4
11: ; preds = %4
%12 = icmp ne i32 %6, 0
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %11, %1
%15 = phi i32 [ -1, %1 ], [ %13, %11 ]
ret i32 %15
}