#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int execl(char *, char *, char *, void *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ prt_retnvalue(int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  int pfd[2];
  int i;
  pid_t pid;
  if (pipe(pfd) < 0) {
    perror("pipe()");
    exit(1);
  }
  pid = fork();
  if (pid < 0) {
    perror("fork()");
    exit(1);
  }
  if (pid == 0) {
    close(pfd[1]);
    dup2(pfd[0], 0);
    i = execl("/usr/local/bin/mpg123", "mpg123",
              "/root/zhang_apue/li_pub/Blowin' In The Wind.mp3", (void *)0);
    prt_retnvalue(i);
    if (i < 0) {
      perror("execl()");
      exit(1);
    }
  } else {
    close(pfd[0]);
    close(pfd[1]);
    wait(NULL);
    exit(0);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jge    11c8 <main+0x38>
lea    0xe47(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11f4 <main+0x64>
lea    0xe22(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    125f <main+0xcf>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1040 <dup2@plt>
lea    0xdf6(%rip),%rdi
lea    0xdfe(%rip),%rsi
lea    0xdfe(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1090 <execl@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <prt_retnvalue@plt>
cmpl   $0x0,-0x10(%rbp)
jge    125a <main+0xca>
lea    0xe09(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    127f <main+0xef>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <wait@plt>
xor    %edi,%edi
call   1080 <exit@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
test   %rax,%rax
jns    11ad <main+0x1d>
lea    0xe55(%rip),%rdi
jmp    1208 <main+0x78>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
jns    11c2 <main+0x32>
lea    0xe47(%rip),%rdi
jmp    1208 <main+0x78>
jne    1217 <main+0x87>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1040 <dup2@plt>
lea    0xe2f(%rip),%rdi
lea    0xe37(%rip),%rsi
lea    0xe37(%rip),%rdx
xor    %ecx,%ecx
call   1090 <execl@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <prt_retnvalue@plt>
test   %ebx,%ebx
jns    1230 <main+0xa0>
lea    0xe4c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10a0 <wait@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"pipe()\00"
@.str.1 = [7 x i8] c"fork()\00"
@.str.2 = [22 x i8] c"/usr/local/bin/mpg123\00"
@.str.3 = [7 x i8] c"mpg123\00"
@.str.4 = [48 x i8] c"/root/zhang_apue/li_pub/Blowin' In The Wind.mp3\00"
@.str.5 = [8 x i8] c"execl()\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i64 @pipe(i32* %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = call i64 (...) @fork()
store i64 %12, i64* %4
%13 = load i64, i64* %4
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = load i64, i64* %4
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %37
21: ; preds = %18
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i32 @close(i32 %23)
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%26 = load i32, i32* %25
%27 = call i32 @dup2(i32 %26, i32 0)
%28 = call i32 @execl(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i8* null)
store i32 %28, i32* %3
%29 = load i32, i32* %3
%30 = call i32 @prt_retnvalue(i32 %29)
%31 = load i32, i32* %3
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %21
%34 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %21
br label %46
37: ; preds = %18
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%39 = load i32, i32* %38
%40 = call i32 @close(i32 %39)
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%42 = load i32, i32* %41
%43 = call i32 @close(i32 %42)
%44 = call i32 @wait(i32* null)
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %36
%47 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"pipe()\00"
@.str.1 = [7 x i8] c"fork()\00"
@.str.2 = [22 x i8] c"/usr/local/bin/mpg123\00"
@.str.3 = [7 x i8] c"mpg123\00"
@.str.4 = [48 x i8] c"/root/zhang_apue/li_pub/Blowin' In The Wind.mp3\00"
@.str.5 = [8 x i8] c"execl()\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%4 = call i64 @pipe(i32* %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = call i64 (...) @fork()
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %9
%16 = icmp eq i64 %10, 0
br i1 %16, label %17, label %29
17: ; preds = %15
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%19 = load i32, i32* %18
%20 = call i32 @close(i32 %19)
%21 = load i32, i32* %3
%22 = call i32 @dup2(i32 %21, i32 0)
%23 = call i32 @execl(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i8* null)
%24 = call i32 @prt_retnvalue(i32 %23)
%25 = icmp slt i32 %23, 0
br i1 %25, label %26, label %37
26: ; preds = %17
%27 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %15
%30 = load i32, i32* %3
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%33 = load i32, i32* %32
%34 = call i32 @close(i32 %33)
%35 = call i32 @wait(i32* null)
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %17
%38 = call i32 @exit(i32 0)
unreachable
}