#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*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int main(void) {
  FILE *pp;
  FILE *fp;
  pp = popen("hcitool scan", "r");
  fp = fopen("/root/btlist.conf", "wb");
  if (pp != NULL) {
    while (1) {
      char *line;
      char buf[1000];
      line = fgets(buf, sizeof buf, pp);
      if (line == NULL)
        break;
      else if (line[0] != 'S') {
        printf("%s", line);
        fprintf(fp, "%s", &line[1]);
      }
    }
    fclose(fp);
    pclose(pp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe6f(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     123d <main+0xcd>
jmp    11c0 <main+0x50>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3e8,%esi
call   1060 <fgets@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e9 <main+0x79>
jmp    122b <main+0xbb>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x53,%eax
je     1221 <main+0xb1>
mov    -0x20(%rbp),%rsi
lea    0xe20(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
add    $0x1,%rdx
lea    0xe08(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1226 <main+0xb6>
jmp    11c0 <main+0x50>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1050 <pclose@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f0,%rsp
lea    0xe79(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,%r13
lea    0xe72(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1090 <fopen@plt>
test   %r13,%r13
je     1229 <main+0xb9>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x3e8,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1219 <main+0xa9>
mov    %rax,%rbx
mov    %rsp,%r15
lea    0xe51(%rip),%r12
jmp    11f8 <main+0x88>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    $0x3e8,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1219 <main+0xa9>
cmpb   $0x53,(%rbx)
je     11e0 <main+0x70>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <fputs@plt>
jmp    11e0 <main+0x70>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r13,%rdi
call   1050 <pclose@plt>
xor    %eax,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"hcitool scan\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"/root/btlist.conf\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca [1000 x i8]
store i32 0, i32* %1
%6 = call i32* @popen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %2
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %38
10: ; preds = %0
br label %11
11: ; preds = %10, %32
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%13 = load i32*, i32** %2
%14 = call i8* @fgets(i8* %12, i32 1000, i32* %13)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %11
br label %33
18: ; preds = %11
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 83
br i1 %23, label %24, label %31
24: ; preds = %18
%25 = load i8*, i8** %4
%26 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %25)
%27 = load i32*, i32** %3
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = call i32 @fprintf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %24, %18
br label %32
32: ; preds = %31
br label %11
33: ; preds = %17
%34 = load i32*, i32** %3
%35 = call i32 @fclose(i32* %34)
%36 = load i32*, i32** %2
%37 = call i32 @pclose(i32* %36)
br label %38
38: ; preds = %33, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"hcitool scan\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"/root/btlist.conf\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = tail call i32* @popen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%4 = icmp eq i32* %2, null
br i1 %4, label %23, label %5
5: ; preds = %0
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%7 = call i8* @fgets(i8* %6, i32 1000, i32* %2)
%8 = icmp eq i8* %7, null
br i1 %8, label %20, label %9
9: ; preds = %5, %17
%10 = phi i8* [ %18, %17 ], [ %7, %5 ]
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 83
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%15 = getelementptr inbounds i8, i8* %10, i64 1
%16 = call i32 @fputs(i8* %15, i32* %3)
br label %17
17: ; preds = %13, %9
%18 = call i8* @fgets(i8* %6, i32 1000, i32* %2)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %9
20: ; preds = %17, %5
%21 = call i32 @fclose(i32* %3)
%22 = call i32 @pclose(i32* %2)
br label %23
23: ; preds = %20, %0
ret i32 0
}