#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ strstr(char *, char *);
int fwmouse_detect_usb() {
  FILE *fp;
  char buf[4097];
  if ((fp = fopen("/proc/bus/usb/devices", "r")) == NULL)
    return (0);
  while ((fread(buf, 1, 4096, fp))) {
    if (strstr(buf, "usb_mouse")) {
      fclose(fp);
      return (1);
    }
  }
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<fwmouse_detect_usb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
lea    0xeae(%rip),%rdi
lea    0xebd(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1178 <fwmouse_detect_usb+0x38>
movl   $0x0,-0x4(%rbp)
jmp    11e8 <fwmouse_detect_usb+0xa8>
jmp    117d <fwmouse_detect_usb+0x3d>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
je     11d8 <fwmouse_detect_usb+0x98>
lea    -0x1020(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     11d3 <fwmouse_detect_usb+0x93>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e8 <fwmouse_detect_usb+0xa8>
jmp    117d <fwmouse_detect_usb+0x3d>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwmouse_detect_usb>:
push   %r15
push   %r14
push   %rbx
sub    $0x1010,%rsp
lea    0xead(%rip),%rdi
lea    0xebc(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11b1 <fwmouse_detect_usb+0x71>
mov    %rax,%r14
mov    %rsp,%rbx
lea    0xea7(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11b5 <fwmouse_detect_usb+0x75>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     1180 <fwmouse_detect_usb+0x40>
mov    $0x1,%ebx
jmp    11b7 <fwmouse_detect_usb+0x77>
xor    %ebx,%ebx
jmp    11bf <fwmouse_detect_usb+0x7f>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x1010,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"/proc/bus/usb/devices\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"usb_mouse\00"
define i32 @fwmouse_detect_usb() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [4097 x i8]
%4 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 0, i32* %1
br label %24
7: ; preds = %0
br label %8
8: ; preds = %20, %7
%9 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 0
%10 = load i32*, i32** %2
%11 = call i64 @fread(i8* %9, i32 1, i32 4096, i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %8
%14 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 0
%15 = call i64 @strstr(i8* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
store i32 1, i32* %1
br label %24
20: ; preds = %13
br label %8
21: ; preds = %8
%22 = load i32*, i32** %2
%23 = call i32 @fclose(i32* %22)
store i32 0, i32* %1
br label %24
24: ; preds = %21, %17, %6
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [22 x i8] c"/proc/bus/usb/devices\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"usb_mouse\00"
define i32 @fwmouse_detect_usb() {
%1 = alloca [4097 x i8]
%2 = getelementptr inbounds [4097 x i8], [4097 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %14, label %5
5: ; preds = %0, %8
%6 = call i64 @fread(i8* %2, i32 1, i32 4096, i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = call i64 @strstr(i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %5, label %11
11: ; preds = %5, %8
%12 = phi i32 [ 1, %8 ], [ 0, %5 ]
%13 = call i32 @fclose(i32* %3)
br label %14
14: ; preds = %11, %0
%15 = phi i32 [ 0, %0 ], [ %12, %11 ]
ret i32 %15
}