#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 atoi(char *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ *strstr(char *, char *);
char *strtok(char *, char *);
int main(void) {
  FILE *pp;
  pp = popen("exec bash automateBluetooth.sh", "r");
  long ret;
  char *ptr;
  if (pp != NULL) {
    while (1) {
      char *line;
      char buf[100000];
      line = fgets(buf, sizeof buf, pp);
      if (line == NULL)
        break;
      if (strstr(line, "RSSI return value:") != NULL) {
        char *pch;
        pch = strtok(line, " ");
        char *a = pch;
        while (pch != NULL) {
          a = pch;
          pch = strtok(NULL, " ,.");
        }
        printf("%d\n", atoi(a));
      }
    }
    pclose(pp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x186e0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1271 <main+0x101>
jmp    11a9 <main+0x39>
lea    -0x186d0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x186a0,%esi
call   1050 <fgets@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d2 <main+0x62>
jmp    1268 <main+0xf8>
mov    -0x28(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     1263 <main+0xf3>
mov    -0x28(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x186d8(%rbp)
mov    -0x186d8(%rbp),%rax
mov    %rax,-0x186e0(%rbp)
cmpq   $0x0,-0x186d8(%rbp)
je     1249 <main+0xd9>
mov    -0x186d8(%rbp),%rax
mov    %rax,-0x186e0(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdfe(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x186d8(%rbp)
jmp    1211 <main+0xa1>
mov    -0x186e0(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%esi
lea    0xddc(%rip),%rdi
call   1030 <printf@plt>
jmp    11a9 <main+0x39>
mov    -0x10(%rbp),%rdi
call   1040 <pclose@plt>
xor    %eax,%eax
add    $0x186e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x186a8,%rsp
lea    0xe78(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     124c <main+0xdc>
mov    %rax,%r13
mov    %rsp,%rdi
mov    $0x186a0,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1244 <main+0xd4>
mov    %rax,%r12
lea    0xe5e(%rip),%r14
mov    %rsp,%r15
lea    0xe69(%rip),%rbp
jmp    1200 <main+0x90>
nop
xor    %ebx,%ebx
mov    %rbx,%rdi
call   1080 <atoi@plt>
lea    0xe59(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    $0x186a0,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
mov    %rax,%r12
test   %rax,%rax
je     1244 <main+0xd4>
mov    %r12,%rdi
mov    %r14,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11e8 <main+0x78>
mov    %r12,%rdi
lea    0xe1a(%rip),%rsi
call   1070 <strtok@plt>
test   %rax,%rax
je     11d0 <main+0x60>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,%rbx
xor    %edi,%edi
mov    %rbp,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
jne    1230 <main+0xc0>
jmp    11d2 <main+0x62>
mov    %r13,%rdi
call   1040 <pclose@plt>
xor    %eax,%eax
add    $0x186a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"exec bash automateBluetooth.sh\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"RSSI return value:\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [4 x i8] c" ,.\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [100000 x i8]
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %1
%9 = call i32* @popen(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %42
12: ; preds = %0
br label %13
13: ; preds = %12, %38
%14 = getelementptr inbounds [100000 x i8], [100000 x i8]* %6, i64 0, i64 0
%15 = load i32*, i32** %2
%16 = call i8* @fgets(i8* %14, i32 100000, i32* %15)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %13
br label %39
20: ; preds = %13
%21 = load i8*, i8** %5
%22 = call i32* @strstr(i8* %21, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %38
24: ; preds = %20
%25 = load i8*, i8** %5
%26 = call i8* @strtok(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %26, i8** %7
%27 = load i8*, i8** %7
store i8* %27, i8** %8
br label %28
28: ; preds = %31, %24
%29 = load i8*, i8** %7
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i8*, i8** %7
store i8* %32, i8** %8
%33 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
store i8* %33, i8** %7
br label %28
34: ; preds = %28
%35 = load i8*, i8** %8
%36 = call i32 @atoi(i8* %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %34, %20
br label %13
39: ; preds = %19
%40 = load i32*, i32** %2
%41 = call i32 @pclose(i32* %40)
br label %42
42: ; preds = %39, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"exec bash automateBluetooth.sh\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"RSSI return value:\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [4 x i8] c" ,.\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [100000 x i8]
%2 = tail call i32* @popen(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %28, label %4
4: ; preds = %0
%5 = getelementptr inbounds [100000 x i8], [100000 x i8]* %1, i64 0, i64 0
%6 = call i8* @fgets(i8* %5, i32 100000, i32* %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %26, label %8
8: ; preds = %4, %23
%9 = phi i8* [ %24, %23 ], [ %6, %4 ]
%10 = call i32* @strstr(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %23, label %12
12: ; preds = %8
%13 = call i8* @strtok(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %12, %15
%16 = phi i8* [ %17, %15 ], [ %13, %12 ]
%17 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %15
19: ; preds = %15, %12
%20 = phi i8* [ null, %12 ], [ %16, %15 ]
%21 = call i32 @atoi(i8* %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %8, %19
%24 = call i8* @fgets(i8* %5, i32 100000, i32* %2)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %8
26: ; preds = %23, %4
%27 = call i32 @pclose(i32* %2)
br label %28
28: ; preds = %26, %0
ret i32 0
}