#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*/ extract_value(char *, char *, char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char, ...);
int setup_device(char *, char *);
scalar_t__ strstr(char *, char *);
int main(int argc, char *argv[]) {
  FILE *usbdev;
  char linebuf[4096];
  char vendor[16], product[16];
  char found_device;
  vendor[0] = 0;
  product[0] = 0;
  found_device = 0;
  if (!(usbdev = fopen("/proc/bus/usb/devices", "r"))) {
    return 1;
  }
  while (fgets(linebuf, 4096, usbdev)) {
    if (strstr(linebuf, "BC125AT")) {
      found_device = 1;
    } else if (!linebuf[0] || !(linebuf[0] >= 'A' && linebuf[0] <= 'Z')) {
      vendor[0] = 0;
      product[0] = 0;
    }
    if (found_device && vendor[0] && product[0])
      break;
    extract_value(linebuf, "Vendor=", vendor);
    extract_value(linebuf, "ProdID=", product);
  }
  if (!found_device) {
    printf("found_device=%d\n", found_device);
    return 1;
  }
  printf("found_device=%d; vendor=%s; product=%s\n", found_device, vendor,
         product);
  return setup_device(vendor, product);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x1030(%rbp)
movb   $0x0,-0x1040(%rbp)
movb   $0x0,-0x1041(%rbp)
lea    0xe6b(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11bb <main+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    131f <main+0x1bf>
jmp    11c0 <main+0x60>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1000,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12b6 <main+0x156>
lea    -0x1020(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1208 <main+0xa8>
movb   $0x1,-0x1041(%rbp)
jmp    1248 <main+0xe8>
cmpb   $0x0,-0x1020(%rbp)
je     1235 <main+0xd5>
movsbl -0x1020(%rbp),%eax
cmp    $0x41,%eax
jl     1235 <main+0xd5>
movsbl -0x1020(%rbp),%eax
cmp    $0x5a,%eax
jle    1243 <main+0xe3>
movb   $0x0,-0x1030(%rbp)
movb   $0x0,-0x1040(%rbp)
jmp    1248 <main+0xe8>
movsbl -0x1041(%rbp),%eax
cmp    $0x0,%eax
je     127d <main+0x11d>
movsbl -0x1030(%rbp),%eax
cmp    $0x0,%eax
je     127d <main+0x11d>
movsbl -0x1040(%rbp),%eax
cmp    $0x0,%eax
je     127d <main+0x11d>
jmp    12b6 <main+0x156>
lea    -0x1020(%rbp),%rdi
lea    -0x1030(%rbp),%rdx
lea    0xd8e(%rip),%rsi
call   1060 <extract_value@plt>
lea    -0x1020(%rbp),%rdi
lea    -0x1040(%rbp),%rdx
lea    0xd7c(%rip),%rsi
call   1060 <extract_value@plt>
jmp    11c0 <main+0x60>
cmpb   $0x0,-0x1041(%rbp)
jne    12e4 <main+0x184>
lea    0xd66(%rip),%rdi
movsbl -0x1041(%rbp),%esi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    131f <main+0x1bf>
mov    -0x1041(%rbp),%al
lea    -0x1030(%rbp),%rdx
lea    -0x1040(%rbp),%rcx
lea    0xd42(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1030(%rbp),%rdi
lea    -0x1040(%rbp),%rsi
call   1030 <setup_device@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
movb   $0x0,0x10(%rsp)
movb   $0x0,(%rsp)
lea    0xe7f(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    $0x1,%eax
test   %rbx,%rbx
je     1294 <main+0x134>
lea    0x20(%rsp),%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     127f <main+0x11f>
xor    %r15d,%r15d
lea    0x20(%rsp),%rbp
lea    0xe60(%rip),%r14
mov    %rsp,%r12
jmp    1207 <main+0xa7>
nopl   (%rax)
mov    %rbp,%rdi
lea    0xe46(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1060 <extract_value@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1060 <extract_value@plt>
mov    %rbp,%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     124c <main+0xec>
mov    %r15d,%r13d
mov    %rbp,%rdi
lea    0xe04(%rip),%rsi
call   1080 <strstr@plt>
mov    $0x1,%r15b
test   %rax,%rax
jne    1238 <main+0xd8>
movzbl 0x20(%rsp),%eax
add    $0xbf,%al
cmp    $0x1a,%al
jb     1235 <main+0xd5>
movb   $0x0,0x10(%rsp)
movb   $0x0,(%rsp)
mov    %r13d,%r15d
test   %r15b,%r15b
je     11d0 <main+0x70>
cmpb   $0x0,0x10(%rsp)
je     11d0 <main+0x70>
cmpb   $0x0,(%rsp)
je     11d0 <main+0x70>
jmp    1251 <main+0xf1>
test   %r15b,%r15b
je     127f <main+0x11f>
lea    0xde9(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rsp,%rbp
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <setup_device@plt>
jmp    1294 <main+0x134>
lea    0xdaa(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"/proc/bus/usb/devices\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"BC125AT\00"
@.str.3 = [8 x i8] c"Vendor=\00"
@.str.4 = [8 x i8] c"ProdID=\00"
@.str.5 = [17 x i8] c"found_device=%d\0A\00"
@.str.6 = [40 x i8] c"found_device=%d; vendor=%s; product=%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [4096 x i8]
%8 = alloca [16 x i8]
%9 = alloca [16 x i8]
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
store i8 0, i8* %11
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
store i8 0, i8* %12
store i8 0, i8* %10
%13 = 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* %13, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %16, label %15
15: ; preds = %2
store i32 1, i32* %3
br label %81
16: ; preds = %2
br label %17
17: ; preds = %60, %16
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%19 = load i32*, i32** %6
%20 = call i64 @fgets(i8* %18, i32 4096, i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %67
22: ; preds = %17
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%24 = call i64 @strstr(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i8 1, i8* %10
br label %45
27: ; preds = %22
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%29 = load i8, i8* %28
%30 = icmp ne i8 %29, 0
br i1 %30, label %31, label %41
31: ; preds = %27
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp sge i32 %34, 65
br i1 %35, label %36, label %41
36: ; preds = %31
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp sle i32 %39, 90
br i1 %40, label %44, label %41
41: ; preds = %36, %31, %27
%42 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
store i8 0, i8* %42
%43 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
store i8 0, i8* %43
br label %44
44: ; preds = %41, %36
br label %45
45: ; preds = %44, %26
%46 = load i8, i8* %10
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %60
49: ; preds = %45
%50 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %60
54: ; preds = %49
%55 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %54
br label %67
60: ; preds = %54, %49, %45
%61 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%62 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%63 = call i32 @extract_value(i8* %61, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %62)
%64 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%65 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%66 = call i32 @extract_value(i8* %64, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %65)
br label %17
67: ; preds = %59, %17
%68 = load i8, i8* %10
%69 = icmp ne i8 %68, 0
br i1 %69, label %73, label %70
70: ; preds = %67
%71 = load i8, i8* %10
%72 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8 signext %71)
store i32 1, i32* %3
br label %81
73: ; preds = %67
%74 = load i8, i8* %10
%75 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%76 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%77 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8 signext %74, i8* %75, i8* %76)
%78 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%79 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%80 = call i32 @setup_device(i8* %78, i8* %79)
store i32 %80, i32* %3
br label %81
81: ; preds = %73, %70, %15
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@.str = [22 x i8] c"/proc/bus/usb/devices\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"BC125AT\00"
@.str.3 = [8 x i8] c"Vendor=\00"
@.str.4 = [8 x i8] c"ProdID=\00"
@.str.5 = [17 x i8] c"found_device=%d\0A\00"
@.str.6 = [40 x i8] c"found_device=%d; vendor=%s; product=%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
store i8 0, i8* %7
store i8 0, i8* %8
%9 = 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))
%10 = icmp eq i32* %9, null
br i1 %10, label %44, label %11
11: ; preds = %2
%12 = call i64 @fgets(i8* %6, i32 4096, i32* %9)
%13 = icmp eq i64 %12, 0
br i1 %13, label %39, label %14
14: ; preds = %11, %32
%15 = phi i8 [ %24, %32 ], [ 0, %11 ]
%16 = call i64 @strstr(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i8, i8* %6
%20 = add i8 %19, -65
%21 = icmp ult i8 %20, 26
br i1 %21, label %23, label %22
22: ; preds = %18
store i8 0, i8* %7
store i8 0, i8* %8
br label %23
23: ; preds = %14, %22, %18
%24 = phi i8 [ %15, %18 ], [ %15, %22 ], [ 1, %14 ]
%25 = icmp ne i8 %24, 0
%26 = load i8, i8* %7
%27 = icmp ne i8 %26, 0
%28 = select i1 %25, i1 %27, i1 false
%29 = load i8, i8* %8
%30 = icmp ne i8 %29, 0
%31 = select i1 %28, i1 %30, i1 false
br i1 %31, label %41, label %32
32: ; preds = %23
%33 = call i32 @extract_value(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%34 = call i32 @extract_value(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%35 = call i64 @fgets(i8* %6, i32 4096, i32* %9)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %14
37: ; preds = %32
%38 = icmp eq i8 %24, 0
br i1 %38, label %39, label %41
39: ; preds = %11, %37
%40 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8 signext 0)
br label %44
41: ; preds = %23, %37
%42 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8 signext 1, i8* %7, i8* %8)
%43 = call i32 @setup_device(i8* %7, i8* %8)
br label %44
44: ; preds = %2, %41, %39
%45 = phi i32 [ %43, %41 ], [ 1, %39 ], [ 1, %2 ]
ret i32 %45
}