#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*/ exit(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
scalar_t__ popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  FILE *fpipe;
  char *command = "/usr/share/application/firefox";
  char line[256];
  if (!(fpipe = (FILE *)popen(command, "r"))) {
    perror("Problems with pipe");
    exit(1);
  }
  while (fgets(line, sizeof line, fpipe)) {
    printf("%s", line);
  }
  pclose(fpipe);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b8 <main+0x58>
lea    0xe78(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11bd <main+0x5d>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11f4 <main+0x94>
lea    -0x120(%rbp),%rsi
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
jmp    11bd <main+0x5d>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe8d(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     11e7 <main+0x87>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11d0 <main+0x70>
lea    0xe91(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11b0 <main+0x50>
mov    %r15,%rdi
call   1040 <pclose@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe33(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"/usr/share/application/firefox\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Problems with pipe\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = load i8*, i8** %7
%10 = call i64 @popen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
br label %17
17: ; preds = %22, %16
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%19 = load i32*, i32** %6
%20 = call i64 @fgets(i8* %18, i32 256, i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %23)
br label %17
25: ; preds = %17
%26 = load i32*, i32** %6
%27 = call i32 @pclose(i32* %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"/usr/share/application/firefox\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Problems with pipe\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @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))
%6 = inttoptr i64 %5 to i32*
%7 = icmp eq i64 %5, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = call i64 @fgets(i8* %4, i32 256, i32* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %14
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8, %14
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%16 = call i64 @fgets(i8* %4, i32 256, i32* %6)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %14
18: ; preds = %14, %8
%19 = call i32 @pclose(i32* %6)
ret i32 0
}