#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 SIGCONT;
int SIGKILL;
int SIGSTOP;
int /*<<< orphan*/ execlp(char *, char *, char *, char *, char *, char *,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
char getchar();
int getpid();
int /*<<< orphan*/ getppid();
int kill(int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char **argv) {
  pid_t child = fork();
  if (child == 0) {
    int n;
    while (1) {
      printf("1: 暂停\n");
      printf("2: 播放\n");
      printf("3: 退出\n");
      scanf("%d", &n);
      switch (n) {
      case 1:
        printf("sending %d to $d\n", SIGSTOP, child);
        if (kill(getppid(), SIGSTOP) == -1) {
          perror("kill failed");
        }
        break;
      case 2:
        kill(getppid(), SIGCONT);
        break;
      case 3:
        kill(getppid(), SIGKILL);
        exit(0);
      default:
        while (getchar() != '\n')
          ;
      }
    }
  }
  if (child > 0) {
    printf("parent: %d\n", getpid());
    execlp("./madplay", "./madplay", "SeeYouAgain.mp3", "-a", "-20", "&", NULL);
    printf("yyy\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12f3 <main+0x153>
jmp    11d1 <main+0x31>
lea    0xe28(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x21(%rbp)
call   1040 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xe1f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xe1b(%rip),%rdi
call   1040 <printf@plt>
lea    0xe1a(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x1,%eax
je     1246 <main+0xa6>
jmp    1224 <main+0x84>
mov    -0x20(%rbp),%eax
sub    $0x2,%eax
je     1292 <main+0xf2>
jmp    1235 <main+0x95>
mov    -0x20(%rbp),%eax
sub    $0x3,%eax
je     12ae <main+0x10e>
jmp    12cc <main+0x12c>
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1090 <getppid@plt>
mov    %eax,%edi
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
cmp    $0xffffffff,%eax
jne    128d <main+0xed>
lea    0xdae(%rip),%rdi
call   1080 <perror@plt>
jmp    12ee <main+0x14e>
mov    $0x0,%al
call   1090 <getppid@plt>
mov    %eax,%edi
mov    0x2d46(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
jmp    12ee <main+0x14e>
mov    $0x0,%al
call   1090 <getppid@plt>
mov    %eax,%edi
mov    0x2d1a(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    12d1 <main+0x131>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     12e9 <main+0x149>
jmp    12d1 <main+0x131>
jmp    12ee <main+0x14e>
jmp    11d1 <main+0x31>
cmpq   $0x0,-0x18(%rbp)
jle    1358 <main+0x1b8>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd32(%rip),%rsi
lea    0xd35(%rip),%rdx
lea    0xd3e(%rip),%rcx
lea    0xd3a(%rip),%r8
lea    0xd37(%rip),%r9
xor    %eax,%eax
mov    %rsi,%rdi
movq   $0x0,(%rsp)
call   10b0 <execlp@plt>
lea    0xd20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
je     1233 <main+0x83>
jle    1222 <main+0x72>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe47(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movq   $0x0,(%rsp)
lea    0xe3b(%rip),%rdi
lea    0xe3e(%rip),%rdx
lea    0xe47(%rip),%rcx
lea    0xe43(%rip),%r8
lea    0xe40(%rip),%r9
mov    %rdi,%rsi
call   10c0 <execlp@plt>
lea    0xe33(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1a(%rip),%r14
lea    0xe1d(%rip),%r15
lea    0xe20(%rip),%r12
lea    0xdb1(%rip),%r13
lea    0x14(%rsp),%rbx
mov    0x2d75(%rip),%rbp
jmp    1277 <main+0xc7>
nopl   (%rax)
xor    %eax,%eax
call   10a0 <getppid@plt>
mov    0x2d7a(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1070 <kill@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    0x14(%rsp),%eax
cmp    $0x1,%eax
je     12c0 <main+0x110>
cmp    $0x2,%eax
je     1260 <main+0xb0>
cmp    $0x3,%eax
je     12f7 <main+0x147>
nopl   (%rax)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
jne    12b0 <main+0x100>
jmp    1277 <main+0xc7>
nopl   (%rax)
mov    0x0(%rbp),%esi
lea    0xd39(%rip),%rdi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   10a0 <getppid@plt>
mov    0x0(%rbp),%esi
mov    %eax,%edi
call   1070 <kill@plt>
cmp    $0xffffffff,%eax
jne    1277 <main+0xc7>
lea    0xd25(%rip),%rdi
call   1090 <perror@plt>
jmp    1277 <main+0xc7>
xor    %eax,%eax
call   10a0 <getppid@plt>
mov    0x2cd3(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1070 <kill@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"1: \E6\9A\82\E5\81\9C\0A\00"
@.str.1 = [11 x i8] c"2: \E6\92\AD\E6\94\BE\0A\00"
@.str.2 = [11 x i8] c"3: \E9\80\80\E5\87\BA\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [18 x i8] c"sending %d to $d\0A\00"
@SIGSTOP = global i32 0
@.str.5 = [12 x i8] c"kill failed\00"
@SIGCONT = global i32 0
@SIGKILL = global i32 0
@.str.6 = [12 x i8] c"parent: %d\0A\00"
@.str.7 = [10 x i8] c"./madplay\00"
@.str.8 = [16 x i8] c"SeeYouAgain.mp3\00"
@.str.9 = [3 x i8] c"-a\00"
@.str.10 = [4 x i8] c"-20\00"
@.str.11 = [2 x i8] c"&\00"
@.str.12 = [5 x i8] c"yyy\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 (...) @fork()
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %46
11: ; preds = %2
br label %12
12: ; preds = %11, %45
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%17 = load i32, i32* %7
switch i32 %17, label %38 [
i32 1, label %18
i32 2, label %29
i32 3, label %33
]
18: ; preds = %12
%19 = load i32, i32* @SIGSTOP
%20 = load i64, i64* %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %19, i64 %20)
%22 = call i32 (...) @getppid()
%23 = load i32, i32* @SIGSTOP
%24 = call i32 @kill(i32 %22, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %28
28: ; preds = %26, %18
br label %45
29: ; preds = %12
%30 = call i32 (...) @getppid()
%31 = load i32, i32* @SIGCONT
%32 = call i32 @kill(i32 %30, i32 %31)
br label %45
33: ; preds = %12
%34 = call i32 (...) @getppid()
%35 = load i32, i32* @SIGKILL
%36 = call i32 @kill(i32 %34, i32 %35)
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %12
br label %39
39: ; preds = %43, %38
%40 = call signext i8 (...) @getchar()
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 10
br i1 %42, label %43, label %44
43: ; preds = %39
br label %39
44: ; preds = %39
br label %45
45: ; preds = %44, %29, %28
br label %12
46: ; preds = %2
%47 = load i64, i64* %6
%48 = icmp sgt i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %46
%50 = call i32 (...) @getpid()
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %50)
%52 = call i32 @execlp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i32* null)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
br label %54
54: ; preds = %49, %46
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [18 x i8] c"sending %d to $d\0A\00"
@SIGSTOP = global i32 0
@.str.5 = [12 x i8] c"kill failed\00"
@SIGCONT = global i32 0
@SIGKILL = global i32 0
@.str.6 = [12 x i8] c"parent: %d\0A\00"
@.str.7 = [10 x i8] c"./madplay\00"
@.str.8 = [16 x i8] c"SeeYouAgain.mp3\00"
@.str.9 = [3 x i8] c"-a\00"
@.str.10 = [4 x i8] c"-20\00"
@.str.11 = [2 x i8] c"&\00"
@str = [4 x i8] c"yyy\00"
@str.13 = [10 x i8] c"1: \E6\9A\82\E5\81\9C\00"
@str.14 = [10 x i8] c"2: \E6\92\AD\E6\94\BE\00"
@str.15 = [10 x i8] c"3: \E9\80\80\E5\87\BA\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %36
6: ; preds = %2
%7 = bitcast i32* %3 to i8*
br label %8
8: ; preds = %21, %6
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.13, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.14, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.15, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%13 = load i32, i32* %3
switch i32 %13, label %33 [
i32 1, label %14
i32 2, label %24
i32 3, label %28
]
14: ; preds = %8
%15 = load i32, i32* @SIGSTOP
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %15, i64 0)
%17 = call i32 (...) @getppid()
%18 = load i32, i32* @SIGSTOP
%19 = call i32 @kill(i32 %17, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %22, label %21
21: ; preds = %33, %14, %22, %24
br label %8
22: ; preds = %14
%23 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %21
24: ; preds = %8
%25 = call i32 (...) @getppid()
%26 = load i32, i32* @SIGCONT
%27 = call i32 @kill(i32 %25, i32 %26)
br label %21
28: ; preds = %8
%29 = call i32 (...) @getppid()
%30 = load i32, i32* @SIGKILL
%31 = call i32 @kill(i32 %29, i32 %30)
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %8, %33
%34 = call signext i8 (...) @getchar()
%35 = icmp eq i8 %34, 10
br i1 %35, label %21, label %33
36: ; preds = %2
%37 = icmp sgt i64 %4, 0
br i1 %37, label %38, label %43
38: ; preds = %36
%39 = tail call i32 (...) @getpid()
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %39)
%41 = tail call i32 @execlp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i32* null)
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
br label %43
43: ; preds = %38, %36
ret i32 0
}