#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 */

/* Variables and functions */
int /*<<< orphan*/ Daughter(int *);
int /*<<< orphan*/ Father(int *);
int /*<<< orphan*/ Son(int *);
int atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  srand((unsigned)time(NULL));
  int plate[5] = {0};
  int count;
  if (argc == 2) {
    count = atoi(argv[1]);
    printf("We will schedule for %d times\n", count);
  } else {
    printf("Please input scheduling count:");
    scanf("%d", &count);
  }
  while (count--) {
    int person = rand() % 3;
    switch (person) {
    case 0:
      printf("sched: father\n");
      Father(plate);
      break;
    case 1:
      printf("sched: son\n");
      Son(plate);
      break;
    case 2:
      printf("sched: daughter\n");
      Daughter(plate);
      break;
    default:
      break;
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
jne    1206 <main+0x66>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1224 <main+0x84>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe23(%rip),%rdi
lea    -0x34(%rbp),%rsi
call   10a0 <scanf@plt>
jmp    1229 <main+0x89>
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x34(%rbp)
cmp    $0x0,%eax
je     1306 <main+0x166>
xor    %eax,%eax
call   10c0 <rand@plt>
movslq %eax,%rcx
imul   $0x55555556,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rdx
add    %ecx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
test   %eax,%eax
je     129a <main+0xfa>
jmp    1278 <main+0xd8>
mov    -0x3c(%rbp),%eax
sub    $0x1,%eax
je     12b6 <main+0x116>
jmp    1289 <main+0xe9>
mov    -0x3c(%rbp),%eax
sub    $0x2,%eax
je     12d2 <main+0x132>
jmp    12ee <main+0x14e>
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <Father@plt>
jmp    12f3 <main+0x153>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1090 <Son@plt>
jmp    12f3 <main+0x153>
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <Daughter@plt>
jmp    12f3 <main+0x153>
jmp    12f3 <main+0x153>
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1229 <main+0x89>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
cmp    $0x2,%ebp
jne    1201 <main+0x51>
mov    0x8(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ebx
lea    0xe0a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1224 <main+0x74>
lea    0xe17(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe28(%rip),%rdi
lea    0xc(%rsp),%rsi
call   10b0 <scanf@plt>
mov    0xc(%rsp),%ebx
sub    $0x1,%ebx
mov    %ebx,0xc(%rsp)
jae    123c <main+0x8c>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfe(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xe02(%rip),%r15
lea    0xe06(%rip),%r12
jmp    1281 <main+0xd1>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   10a0 <Son@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
subl   $0x1,0xc(%rsp)
jb     122d <main+0x7d>
xor    %eax,%eax
call   10d0 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
cmp    $0x2,%eax
je     12d0 <main+0x120>
cmp    $0x1,%eax
je     1260 <main+0xb0>
test   %eax,%eax
jne    1270 <main+0xc0>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1060 <Father@plt>
jmp    1270 <main+0xc0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <Daughter@plt>
jmp    1270 <main+0xc0>

LLVM IR (-O0):
@.str = [31 x i8] c"We will schedule for %d times\0A\00"
@.str.1 = [31 x i8] c"Please input scheduling count:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [15 x i8] c"sched: father\0A\00"
@.str.4 = [12 x i8] c"sched: son\0A\00"
@.str.5 = [17 x i8] c"sched: daughter\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [5 x i32]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i64 @time(i32* null)
%10 = trunc i64 %9 to i32
%11 = call i32 @srand(i32 %10)
%12 = bitcast [5 x i32]* %6 to i8*
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %25
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
br label %25
25: ; preds = %22, %15
br label %26
26: ; preds = %47, %25
%27 = load i32, i32* %7
%28 = add nsw i32 %27, -1
store i32 %28, i32* %7
%29 = icmp ne i32 %27, 0
br i1 %29, label %30, label %49
30: ; preds = %26
%31 = call i32 (...) @rand()
%32 = srem i32 %31, 3
store i32 %32, i32* %8
%33 = load i32, i32* %8
switch i32 %33, label %46 [
i32 0, label %34
i32 1, label %38
i32 2, label %42
]
34: ; preds = %30
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%36 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 0
%37 = call i32 @Father(i32* %36)
br label %47
38: ; preds = %30
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%40 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 0
%41 = call i32 @Son(i32* %40)
br label %47
42: ; preds = %30
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%44 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 0
%45 = call i32 @Daughter(i32* %44)
br label %47
46: ; preds = %30
br label %47
47: ; preds = %46, %42, %38, %34
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %26
49: ; preds = %26
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [31 x i8] c"We will schedule for %d times\0A\00"
@.str.1 = [31 x i8] c"Please input scheduling count:\00"
@.str.2 = [3 x i8] c"%d\00"
@str = [16 x i8] c"sched: daughter\00"
@str.7 = [11 x i8] c"sched: son\00"
@str.8 = [14 x i8] c"sched: father\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [5 x i32]
%4 = alloca i32
%5 = tail call i64 @time(i32* null)
%6 = trunc i64 %5 to i32
%7 = tail call i32 @srand(i32 %6)
%8 = bitcast [5 x i32]* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = icmp eq i32 %0, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %20
16: ; preds = %2
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%19 = load i32, i32* %4
br label %20
20: ; preds = %16, %11
%21 = phi i32 [ %19, %16 ], [ %14, %11 ]
%22 = add nsw i32 %21, -1
store i32 %22, i32* %4
%23 = icmp eq i32 %21, 0
br i1 %23, label %43, label %24
24: ; preds = %20
%25 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
br label %26
26: ; preds = %24, %38
%27 = call i32 (...) @rand()
%28 = srem i32 %27, 3
switch i32 %28, label %38 [
i32 0, label %29
i32 1, label %32
i32 2, label %35
]
29: ; preds = %26
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.8, i64 0, i64 0))
%31 = call i32 @Father(i32* %25)
br label %38
32: ; preds = %26
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.7, i64 0, i64 0))
%34 = call i32 @Son(i32* %25)
br label %38
35: ; preds = %26
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%37 = call i32 @Daughter(i32* %25)
br label %38
38: ; preds = %26, %35, %32, %29
%39 = call i32 @putchar(i32 10)
%40 = load i32, i32* %4
%41 = add nsw i32 %40, -1
store i32 %41, i32* %4
%42 = icmp eq i32 %40, 0
br i1 %42, label %43, label %26
43: ; preds = %38, %20
ret i32 0
}