#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*/ assert(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char const *, char *);
int /*<<< orphan*/ show_pid(char *);
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int main(int argc, char *argv[]) {
  FILE *fp;
  char buffer[4096];
  bool have_broser = false;
  const char *b2g_ps = "adb shell b2g-ps";
  fp = popen(b2g_ps, "r");
  assert(fp);
  while (fgets(buffer, 4095, fp) != NULL) {
    if (buffer[strlen(buffer) - 1] == '\n') {
      buffer[strlen(buffer) - 1] = 0;
    }
    if (!strncmp(buffer, "Browser", 7)) {
      have_broser = true;
      show_pid(buffer);
    } else if (!strncmp(buffer, "CastApp", 7)) {
      have_broser = true;
      show_pid(buffer);
    }
  }
  pclose(fp);
  if (!have_broser) {
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1024(%rbp)
lea    0xe56(%rip),%rax
mov    %rax,-0x1030(%rbp)
mov    -0x1030(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <assert@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xfff,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12a8 <main+0x128>
lea    -0x1020(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x1020(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    122b <main+0xab>
lea    -0x1020(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x1020(%rbp,%rax,1)
lea    -0x1020(%rbp),%rdi
lea    0xdd8(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1267 <main+0xe7>
movl   $0x1,-0x1024(%rbp)
lea    -0x1020(%rbp),%rdi
call   1080 <show_pid@plt>
jmp    12a3 <main+0x123>
lea    -0x1020(%rbp),%rdi
lea    0xda4(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    129e <main+0x11e>
movl   $0x1,-0x1024(%rbp)
lea    -0x1020(%rbp),%rdi
call   1080 <show_pid@plt>
jmp    12a3 <main+0x123>
jmp    11d1 <main+0x51>
mov    -0x18(%rbp),%rdi
call   1050 <pclose@plt>
cmpl   $0x0,-0x1024(%rbp)
jne    12c8 <main+0x148>
mov    $0x1,%edi
call   10a0 <exit@plt>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1000,%rsp
lea    0xe6a(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <assert@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xfff,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     126a <main+0xea>
xor    %ebp,%ebp
lea    0xe3f(%rip),%r15
lea    0xe40(%rip),%r12
jmp    1202 <main+0x82>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <show_pid@plt>
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    $0xfff,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     124c <main+0xcc>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1222 <main+0xa2>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11e0 <main+0x60>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11ed <main+0x6d>
jmp    11e0 <main+0x60>
mov    %r14,%rdi
call   1050 <pclose@plt>
test   %ebp,%ebp
je     1272 <main+0xf2>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1050 <pclose@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"adb shell b2g-ps\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"Browser\00"
@.str.3 = [8 x i8] c"CastApp\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 i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load i8*, i8** %9
%11 = call i32* @popen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = call i32 @assert(i32* %12)
br label %14
14: ; preds = %49, %2
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%16 = load i32*, i32** %6
%17 = call i32* @fgets(i8* %15, i32 4095, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %50
19: ; preds = %14
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %34
28: ; preds = %19
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %28, %19
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%36 = call i32 @strncmp(i8* %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%37 = icmp ne i32 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %34
store i32 1, i32* %8
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%40 = call i32 @show_pid(i8* %39)
br label %49
41: ; preds = %34
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%43 = call i32 @strncmp(i8* %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
%44 = icmp ne i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %41
store i32 1, i32* %8
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%47 = call i32 @show_pid(i8* %46)
br label %48
48: ; preds = %45, %41
br label %49
49: ; preds = %48, %38
br label %14
50: ; preds = %14
%51 = load i32*, i32** %6
%52 = call i32 @pclose(i32* %51)
%53 = load i32, i32* %8
%54 = icmp ne i32 %53, 0
br i1 %54, label %57, label %55
55: ; preds = %50
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %50
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"adb shell b2g-ps\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"Browser\00"
@.str.3 = [8 x i8] c"CastApp\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @popen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @assert(i32* %5)
%7 = call i32* @fgets(i8* %4, i32 4095, i32* %5)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @pclose(i32* %5)
br label %39
11: ; preds = %2, %32
%12 = phi i32 [ %33, %32 ], [ 0, %2 ]
%13 = call i32 @strlen(i8* %4)
%14 = add nsw i32 %13, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 10
br i1 %18, label %19, label %24
19: ; preds = %11
%20 = call i32 @strlen(i8* %4)
%21 = add nsw i32 %20, -1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %19, %11
%25 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%26 = icmp eq i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27, %24
%31 = call i32 @show_pid(i8* %4)
br label %32
32: ; preds = %30, %27
%33 = phi i32 [ %12, %27 ], [ 1, %30 ]
%34 = call i32* @fgets(i8* %4, i32 4095, i32* %5)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %11
36: ; preds = %32
%37 = call i32 @pclose(i32* %5)
%38 = icmp eq i32 %33, 0
br i1 %38, label %39, label %41
39: ; preds = %9, %36
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %36
ret i32 0
}