#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int usb_scan_devices(int *bus, int *dev) {
  FILE *devs_file = fopen("/proc/bus/usb/"
                          "devices",
                          "r");
  int current_bus = -1;
  int current_dev = -1;
  int ch;
  if (NULL == devs_file) {
    fprintf(stderr, "Error: unable to access "
                    "/proc/bus/usb/"
                    "devices\n");
    return 0;
  }
  ch = getc(devs_file);
  while (EOF != ch) {
    if ('T' == ch) {
      if (2 != fscanf(devs_file, ":  Bus=%d %*[^D\n]Dev#=%d", &current_bus,
                      &current_dev)) {
        current_bus = -1;
        current_dev = -1;
      }
    } else if ('S' == ch) {
      int start = 0, end = 0;
      if (EOF != fscanf(devs_file,
                        ":  Product=%n"
                        "Red Hat eCos USB test"
                        "%n",
                        &start, &end)) {
        if (start < end) {
          *bus = current_bus;
          *dev = current_dev;
          break;
        }
      }
    }
    while ((EOF != ch) && ('\n' != ch)) {
      ch = getc(devs_file);
    }
    if (EOF != ch) {
      ch = getc(devs_file);
    }
  }
  fclose(devs_file);
  if ((-1 != *bus) && (-1 != *dev)) {
    return 1;
  }
  fprintf(stderr, "Error: failed to find a USB device \""
                  "Red Hat eCos USB test"
                  "\"\n");
  return 0;
}


x86 assembly (clang, -O0):
<usb_scan_devices>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe99(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0xffffffff,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11b2 <usb_scan_devices+0x62>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1358 <usb_scan_devices+0x208>
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
cmp    -0x2c(%rbp),%eax
je     1305 <usb_scan_devices+0x1b5>
mov    $0x54,%eax
cmp    -0x2c(%rbp),%eax
jne    1218 <usb_scan_devices+0xc8>
mov    -0x20(%rbp),%rdi
lea    0xe5e(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1040 <fscanf@plt>
mov    %eax,%ecx
mov    $0x2,%eax
cmp    %ecx,%eax
je     1213 <usb_scan_devices+0xc3>
movl   $0xffffffff,-0x24(%rbp)
movl   $0xffffffff,-0x28(%rbp)
jmp    1297 <usb_scan_devices+0x147>
mov    $0x53,%eax
cmp    -0x2c(%rbp),%eax
jne    1292 <usb_scan_devices+0x142>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe15(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x34(%rbp),%rcx
call   1040 <fscanf@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
je     128d <usb_scan_devices+0x13d>
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1288 <usb_scan_devices+0x138>
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1305 <usb_scan_devices+0x1b5>
jmp    128d <usb_scan_devices+0x13d>
jmp    1292 <usb_scan_devices+0x142>
jmp    1297 <usb_scan_devices+0x147>
jmp    129c <usb_scan_devices+0x14c>
mov    0x2d45(%rip),%rax
mov    (%rax),%ecx
xor    %eax,%eax
cmp    -0x2c(%rbp),%ecx
mov    %al,-0x39(%rbp)
je     12c1 <usb_scan_devices+0x171>
mov    $0xa,%eax
cmp    -0x2c(%rbp),%eax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    12d1 <usb_scan_devices+0x181>
jmp    12e2 <usb_scan_devices+0x192>
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x2c(%rbp)
jmp    129c <usb_scan_devices+0x14c>
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
cmp    -0x2c(%rbp),%eax
je     1300 <usb_scan_devices+0x1b0>
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x2c(%rbp)
jmp    11be <usb_scan_devices+0x6e>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rcx
mov    $0xffffffff,%eax
cmp    (%rcx),%eax
je     133c <usb_scan_devices+0x1ec>
mov    -0x18(%rbp),%rcx
mov    $0xffffffff,%eax
cmp    (%rcx),%eax
je     133c <usb_scan_devices+0x1ec>
movl   $0x1,-0x4(%rbp)
jmp    1358 <usb_scan_devices+0x208>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
lea    0xd39(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usb_scan_devices>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xe95(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
movl   $0xffffffff,0xc(%rsp)
ff
movl   $0xffffffff,0x8(%rsp)
ff
test   %rax,%rax
je     11e4 <usb_scan_devices+0x94>
mov    %rax,%rbx
mov    %rbp,0x20(%rsp)
mov    %r14,0x18(%rsp)
mov    %rax,%rdi
call   1070 <getc@plt>
mov    0x2e40(%rip),%rbp
mov    0x0(%rbp),%r14d
cmp    %eax,%r14d
jne    120a <usb_scan_devices+0xba>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x20(%rsp),%rax
cmpl   $0xffffffff,(%rax)
je     11d2 <usb_scan_devices+0x82>
mov    $0x1,%eax
mov    0x18(%rsp),%rcx
cmpl   $0xffffffff,(%rcx)
jne    11fb <usb_scan_devices+0xab>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
jmp    11f4 <usb_scan_devices+0xa4>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r15d
lea    0xc(%rsp),%r12
lea    0x8(%rsp),%r13
jmp    1225 <usb_scan_devices+0xd5>
nopl   0x0(%rax)
cmp    %r15d,%r14d
je     11b1 <usb_scan_devices+0x61>
cmp    $0x53,%r15d
je     1260 <usb_scan_devices+0x110>
cmp    $0x54,%r15d
jne    12a0 <usb_scan_devices+0x150>
mov    %rbx,%rdi
lea    0xe0c(%rip),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1040 <fscanf@plt>
cmp    $0x2,%eax
je     12a0 <usb_scan_devices+0x150>
movl   $0xffffffff,0xc(%rsp)
ff
movl   $0xffffffff,0x8(%rsp)
ff
jmp    12a0 <usb_scan_devices+0x150>
nopl   (%rax)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
mov    %rbx,%rdi
lea    0xde6(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1040 <fscanf@plt>
cmp    %eax,%r14d
je     12a0 <usb_scan_devices+0x150>
mov    0x14(%rsp),%eax
cmp    0x10(%rsp),%eax
jl     12fc <usb_scan_devices+0x1ac>
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%r14d
cmp    %r15d,%r14d
nopw   0x0(%rax,%rax,1)
setne  %al
cmp    $0xa,%r15d
je     12e0 <usb_scan_devices+0x190>
cmp    %r15d,%r14d
je     12e0 <usb_scan_devices+0x190>
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,%r15d
mov    0x0(%rbp),%r14d
cmp    %eax,%r14d
jmp    12b0 <usb_scan_devices+0x160>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %al,%al
je     1220 <usb_scan_devices+0xd0>
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,%r15d
mov    0x0(%rbp),%r14d
jmp    1220 <usb_scan_devices+0xd0>
mov    0xc(%rsp),%eax
mov    0x20(%rsp),%rcx
mov    %eax,(%rcx)
mov    0x8(%rsp),%eax
mov    0x18(%rsp),%rcx
mov    %eax,(%rcx)
jmp    11b1 <usb_scan_devices+0x61>

LLVM IR (-O0):
@.str = [22 x i8] c"/proc/bus/usb/devices\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [47 x i8] c"Error: unable to access /proc/bus/usb/devices\0A\00"
@EOF = global i32 0
@.str.3 = [25 x i8] c": Bus=%d %*[^D\0A]Dev#=%d\00"
@.str.4 = [37 x i8] c": Product=%nRed Hat eCos USB test%n\00"
@.str.5 = [60 x i8] c"Error: failed to find a USB device \22Red Hat eCos USB test\22\0A\00"
define i32 @usb_scan_devices(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%12 = 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* %12, i32** %6
store i32 -1, i32* %7
store i32 -1, i32* %8
%13 = load i32*, i32** %6
%14 = icmp eq i32* null, %13
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %89
18: ; preds = %2
%19 = load i32*, i32** %6
%20 = call i32 @getc(i32* %19)
store i32 %20, i32* %9
br label %21
21: ; preds = %74, %18
%22 = load i32, i32* @EOF
%23 = load i32, i32* %9
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %75
25: ; preds = %21
%26 = load i32, i32* %9
%27 = icmp eq i32 84, %26
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i32*, i32** %6
%30 = call i32 @fscanf(i32* %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32* %7, i32* %8)
%31 = icmp ne i32 2, %30
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 -1, i32* %7
store i32 -1, i32* %8
br label %33
33: ; preds = %32, %28
br label %54
34: ; preds = %25
%35 = load i32, i32* %9
%36 = icmp eq i32 83, %35
br i1 %36, label %37, label %53
37: ; preds = %34
store i32 0, i32* %10
store i32 0, i32* %11
%38 = load i32, i32* @EOF
%39 = load i32*, i32** %6
%40 = call i32 @fscanf(i32* %39, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32* %10, i32* %11)
%41 = icmp ne i32 %38, %40
br i1 %41, label %42, label %52
42: ; preds = %37
%43 = load i32, i32* %10
%44 = load i32, i32* %11
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %51
46: ; preds = %42
%47 = load i32, i32* %7
%48 = load i32*, i32** %4
store i32 %47, i32* %48
%49 = load i32, i32* %8
%50 = load i32*, i32** %5
store i32 %49, i32* %50
br label %75
51: ; preds = %42
br label %52
52: ; preds = %51, %37
br label %53
53: ; preds = %52, %34
br label %54
54: ; preds = %53, %33
br label %55
55: ; preds = %64, %54
%56 = load i32, i32* @EOF
%57 = load i32, i32* %9
%58 = icmp ne i32 %56, %57
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = load i32, i32* %9
%61 = icmp ne i32 10, %60
br label %62
62: ; preds = %59, %55
%63 = phi i1 [ false, %55 ], [ %61, %59 ]
br i1 %63, label %64, label %67
64: ; preds = %62
%65 = load i32*, i32** %6
%66 = call i32 @getc(i32* %65)
store i32 %66, i32* %9
br label %55
67: ; preds = %62
%68 = load i32, i32* @EOF
%69 = load i32, i32* %9
%70 = icmp ne i32 %68, %69
br i1 %70, label %71, label %74
71: ; preds = %67
%72 = load i32*, i32** %6
%73 = call i32 @getc(i32* %72)
store i32 %73, i32* %9
br label %74
74: ; preds = %71, %67
br label %21
75: ; preds = %46, %21
%76 = load i32*, i32** %6
%77 = call i32 @fclose(i32* %76)
%78 = load i32*, i32** %4
%79 = load i32, i32* %78
%80 = icmp ne i32 -1, %79
br i1 %80, label %81, label %86
81: ; preds = %75
%82 = load i32*, i32** %5
%83 = load i32, i32* %82
%84 = icmp ne i32 -1, %83
br i1 %84, label %85, label %86
85: ; preds = %81
store i32 1, i32* %3
br label %89
86: ; preds = %81, %75
%87 = load i32, i32* @stderr
%88 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %89
89: ; preds = %86, %85, %15
%90 = load i32, i32* %3
ret i32 %90
}

LLVM IR (-O2):
@.str = [22 x i8] c"/proc/bus/usb/devices\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [47 x i8] c"Error: unable to access /proc/bus/usb/devices\0A\00"
@EOF = global i32 0
@.str.3 = [25 x i8] c": Bus=%d %*[^D\0A]Dev#=%d\00"
@.str.4 = [37 x i8] c": Product=%nRed Hat eCos USB test%n\00"
@.str.5 = [60 x i8] c"Error: failed to find a USB device \22Red Hat eCos USB test\22\0A\00"
define i32 @usb_scan_devices(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = 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))
%8 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%9 = bitcast i32* %4 to i8*
store i32 -1, i32* %4
%10 = icmp eq i32* %7, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
br label %71
14: ; preds = %2
%15 = tail call i32 @getc(i32* %7)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %16, %15
br i1 %17, label %61, label %18
18: ; preds = %14
%19 = bitcast i32* %5 to i8*
%20 = bitcast i32* %6 to i8*
br label %21
21: ; preds = %18, %57
%22 = phi i32 [ %16, %18 ], [ %58, %57 ]
%23 = phi i32 [ %15, %18 ], [ %59, %57 ]
switch i32 %23, label %39 [
i32 84, label %24
i32 83, label %28
]
24: ; preds = %21
%25 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4)
%26 = icmp eq i32 %25, 2
br i1 %26, label %39, label %27
27: ; preds = %24
store i32 -1, i32* %3
store i32 -1, i32* %4
br label %39
28: ; preds = %21
store i32 0, i32* %5
store i32 0, i32* %6
%29 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32* %5, i32* %6)
%30 = icmp eq i32 %22, %29
br i1 %30, label %35, label %31
31: ; preds = %28
%32 = load i32, i32* %5
%33 = load i32, i32* %6
%34 = icmp slt i32 %32, %33
br i1 %34, label %36, label %35
35: ; preds = %31, %28
br label %39
36: ; preds = %31
%37 = load i32, i32* %3
store i32 %37, i32* %0
%38 = load i32, i32* %4
store i32 %38, i32* %1
br label %61
39: ; preds = %35, %21, %24, %27
%40 = load i32, i32* @EOF
%41 = icmp ne i32 %40, %23
%42 = icmp ne i32 %23, 10
%43 = and i1 %42, %41
br i1 %43, label %44, label %50
44: ; preds = %39, %44
%45 = call i32 @getc(i32* %7)
%46 = load i32, i32* @EOF
%47 = icmp ne i32 %46, %45
%48 = icmp ne i32 %45, 10
%49 = and i1 %48, %47
br i1 %49, label %44, label %50
50: ; preds = %44, %39
%51 = phi i32 [ %40, %39 ], [ %46, %44 ]
%52 = phi i32 [ %23, %39 ], [ %45, %44 ]
%53 = phi i1 [ %41, %39 ], [ %47, %44 ]
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = call i32 @getc(i32* %7)
%56 = load i32, i32* @EOF
br label %57
57: ; preds = %54, %50
%58 = phi i32 [ %56, %54 ], [ %51, %50 ]
%59 = phi i32 [ %55, %54 ], [ %52, %50 ]
%60 = icmp eq i32 %58, %59
br i1 %60, label %61, label %21
61: ; preds = %57, %14, %36
%62 = call i32 @fclose(i32* %7)
%63 = load i32, i32* %0
%64 = icmp eq i32 %63, -1
br i1 %64, label %68, label %65
65: ; preds = %61
%66 = load i32, i32* %1
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %71
68: ; preds = %65, %61
%69 = load i32, i32* @stderr
%70 = call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0))
br label %71
71: ; preds = %65, %68, %11
%72 = phi i32 [ 0, %11 ], [ 0, %68 ], [ 1, %65 ]
ret i32 %72
}