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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
int getPlayingSong(char *pszSong) {
  FILE *fp = popen("rhythmbox-client --print-playing", "r");
  if (fp == NULL) {
    printf("Failed to 'print-playing'");
    return 1;
  }
  while (fgets(pszSong, sizeof(pszSong) - 1, fp) != NULL)
    ;
  pclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<getPlayingSong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
lea    0xec7(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1186 <getPlayingSong+0x46>
lea    0xeae(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11bc <getPlayingSong+0x7c>
jmp    118b <getPlayingSong+0x4b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x7,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11ac <getPlayingSong+0x6c>
jmp    118b <getPlayingSong+0x4b>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPlayingSong>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rdi
lea    0xecc(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     1191 <getPlayingSong+0x51>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x7,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1170 <getPlayingSong+0x30>
mov    %rbx,%rdi
call   1040 <pclose@plt>
xor    %eax,%eax
jmp    11a2 <getPlayingSong+0x62>
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [33 x i8] c"rhythmbox-client --print-playing\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Failed to 'print-playing'\00"
define i32 @getPlayingSong(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = call i32* @popen(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %4
%6 = load i32*, i32** %4
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %20
10: ; preds = %1
br label %11
11: ; preds = %16, %10
%12 = load i8*, i8** %3
%13 = load i32*, i32** %4
%14 = call i32* @fgets(i8* %12, i32 7, i32* %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %11
br label %11
17: ; preds = %11
%18 = load i32*, i32** %4
%19 = call i32 @pclose(i32* %18)
store i32 0, i32* %2
br label %20
20: ; preds = %17, %8
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@.str = [33 x i8] c"rhythmbox-client --print-playing\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Failed to 'print-playing'\00"
define i32 @getPlayingSong(i8* %0) {
%2 = tail call i32* @popen(i8* getelementptr inbounds ([33 x i8], [33 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 %4, label %6
4: ; preds = %1
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %11
6: ; preds = %1, %6
%7 = tail call i32* @fgets(i8* %0, i32 7, i32* %2)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %6
9: ; preds = %6
%10 = tail call i32 @pclose(i32* %2)
br label %11
11: ; preds = %9, %4
%12 = phi i32 [ 1, %4 ], [ 0, %9 ]
ret i32 %12
}