#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 */
scalar_t__ get_line_queue(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ unget_line_queue(char *);
void test_get_line_queue(void) {
  char buffer[1024];
  FILE *p;
  int i = 0;
  p = popen("(echo one;echo two;echo three;echo four)", "r");
  while (get_line_queue(buffer, p)) {
    if (++i == 1) {
      printf("%s\n", buffer);
      unget_line_queue(buffer);
    } else {
      printf("%s\n", buffer);
    }
  }
  pclose(p);
}


x86 assembly (clang, -O0):
<test_get_line_queue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x40c(%rbp)
lea    0xe94(%rip),%rdi
lea    0xeb6(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x408(%rbp)
lea    -0x400(%rbp),%rdi
mov    -0x408(%rbp),%rsi
call   1050 <get_line_queue@plt>
cmp    $0x0,%rax
je     11f0 <test_get_line_queue+0xa0>
mov    -0x40c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40c(%rbp)
cmp    $0x1,%eax
jne    11d8 <test_get_line_queue+0x88>
lea    -0x400(%rbp),%rsi
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
lea    -0x400(%rbp),%rdi
call   1060 <unget_line_queue@plt>
jmp    11eb <test_get_line_queue+0x9b>
lea    -0x400(%rbp),%rsi
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
jmp    117f <test_get_line_queue+0x2f>
mov    -0x408(%rbp),%rdi
call   1040 <pclose@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_get_line_queue>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
lea    0xe9d(%rip),%rdi
lea    0xebf(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    %rax,%rsi
call   1050 <get_line_queue@plt>
test   %rax,%rax
je     11db <test_get_line_queue+0x8b>
lea    0xea2(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1060 <unget_line_queue@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <get_line_queue@plt>
test   %rax,%rax
je     11db <test_get_line_queue+0x8b>
lea    0xe78(%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    %r15,%rsi
call   1050 <get_line_queue@plt>
test   %rax,%rax
jne    11c0 <test_get_line_queue+0x70>
mov    %r15,%rdi
call   1040 <pclose@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"(echo one;echo two;echo three;echo four)\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @test_get_line_queue() {
%1 = alloca [1024 x i8]
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %3
%4 = call i32* @popen(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
br label %5
5: ; preds = %22, %0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%7 = load i32*, i32** %2
%8 = call i64 @get_line_queue(i8* %6, i32* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %5
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
store i32 %12, i32* %3
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%18 = call i32 @unget_line_queue(i8* %17)
br label %22
19: ; preds = %10
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19, %14
br label %5
23: ; preds = %5
%24 = load i32*, i32** %2
%25 = call i32 @pclose(i32* %24)
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"(echo one;echo two;echo three;echo four)\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @test_get_line_queue() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @popen(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = call i64 @get_line_queue(i8* %2, i32* %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%8 = call i32 @unget_line_queue(i8* %2)
%9 = call i64 @get_line_queue(i8* %2, i32* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %6, %11
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%13 = call i64 @get_line_queue(i8* %2, i32* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %11
15: ; preds = %11, %6, %0
%16 = call i32 @pclose(i32* %3)
ret void
}