#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(char const *, char *);
int /*<<< orphan*/ show_browser_pid(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int main(int argc, char *argv[]) {
  FILE *fp;
  char buffer[4096];
  const char *cmd = "adb shell b2g-ps";
  if ((fp = popen(cmd, "r")) == NULL) {
    perror("popen failed");
    exit(1);
  }
  while (fgets(buffer, sizeof(buffer), fp) != NULL) {
    if (!strncmp(buffer, "Browser", 7)) {
      show_browser_pid(buffer);
    } else if (!strncmp(buffer, "CastApp", 7)) {
      show_browser_pid(buffer);
    }
  }
  pclose(fp);
  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)
lea    0xe70(%rip),%rax
mov    %rax,-0x1028(%rbp)
mov    -0x1028(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ce <main+0x5e>
lea    0xe52(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11d3 <main+0x63>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1000,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     125b <main+0xeb>
lea    -0x1020(%rbp),%rdi
lea    0xe1e(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1224 <main+0xb4>
lea    -0x1020(%rbp),%rdi
call   1080 <show_browser_pid@plt>
jmp    1256 <main+0xe6>
lea    -0x1020(%rbp),%rdi
lea    0xdf4(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1251 <main+0xe1>
lea    -0x1020(%rbp),%rdi
call   1080 <show_browser_pid@plt>
jmp    1256 <main+0xe6>
jmp    11d3 <main+0x63>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1008,%rsp
lea    0xe7b(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     1230 <main+0xc0>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1217 <main+0xa7>
lea    0xe65(%rip),%r14
mov    %rsp,%rbx
lea    0xe63(%rip),%r12
jmp    11ed <main+0x7d>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1080 <show_browser_pid@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1217 <main+0xa7>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11d0 <main+0x60>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11d8 <main+0x68>
jmp    11d0 <main+0x60>
mov    %r15,%rdi
call   1040 <pclose@plt>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdda(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <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 = [13 x i8] c"popen failed\00"
@.str.3 = [8 x i8] c"Browser\00"
@.str.4 = [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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %8
%9 = load i8*, i8** %8
%10 = call i32* @popen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
br label %16
16: ; preds = %36, %15
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%18 = load i32*, i32** %6
%19 = call i32* @fgets(i8* %17, i32 4096, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %37
21: ; preds = %16
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%23 = call i32 @strncmp(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
%24 = icmp ne i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%27 = call i32 @show_browser_pid(i8* %26)
br label %36
28: ; preds = %21
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%30 = call i32 @strncmp(i8* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7)
%31 = icmp ne i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%34 = call i32 @show_browser_pid(i8* %33)
br label %35
35: ; preds = %32, %28
br label %36
36: ; preds = %35, %25
br label %16
37: ; preds = %16
%38 = load i32*, i32** %6
%39 = call i32 @pclose(i32* %38)
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 = [13 x i8] c"popen failed\00"
@.str.3 = [8 x i8] c"Browser\00"
@.str.4 = [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 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %4, i32 4096, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %24, label %13
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7, %21
%14 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 7)
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16, %13
%20 = call i32 @show_browser_pid(i8* %4)
br label %21
21: ; preds = %19, %16
%22 = call i32* @fgets(i8* %4, i32 4096, i32* %5)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %13
24: ; preds = %21, %7
%25 = call i32 @pclose(i32* %5)
ret i32 0
}