#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 */
struct sched_param {
  scalar_t__ sched_priority;
};
typedef int pid_t;

/* Variables and functions */
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ syscall(int, int, int, struct sched_param *);
int /*<<< orphan*/ wait(int);
int main() {
  struct sched_param param;
  param.sched_priority = 0;
  pid_t pid = getpid();
  printf("before setschedule 1, pid: %d", pid);
  syscall(156, pid, 6, &param);
  int sch = -1;
  int number = 1;
  int i;
  printf("before first fork\n");
  if (fork() == 0) {
    pid = getpid();
    printf("before setschedule 2, pid: %d\n", pid);
    syscall(156, pid, 6, &param);
    number++;
    if (fork() == 0) {
      pid = getpid();
      printf("before setschedule 3, pid: %d\n", pid);
      printf("before setschedule 3\n");
      syscall(156, pid, 6, &param);
      number++;
    }
  }
  for (i = 0; i < 10; i++) {
    printf("\nnumber %d, process: %d\n", number, pid);
    wait(100);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
mov    $0x9c,%edi
mov    $0x6,%edx
lea    -0x10(%rbp),%rcx
call   1050 <syscall@plt>
movl   $0xffffffff,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
jne    125d <main+0x10d>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
mov    $0x9c,%edi
mov    $0x6,%edx
lea    -0x10(%rbp),%rcx
call   1050 <syscall@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
jne    1258 <main+0x108>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
mov    $0x9c,%edi
mov    $0x6,%edx
lea    -0x10(%rbp),%rcx
call   1050 <syscall@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    125d <main+0x10d>
movl   $0x0,-0x20(%rbp)
cmpl   $0xa,-0x20(%rbp)
jge    129a <main+0x14a>
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x64,%edi
call   1060 <wait@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1264 <main+0x114>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
lea    0xe7f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rcx
mov    $0x9c,%edi
mov    %ebx,%esi
mov    $0x6,%edx
call   1060 <syscall@plt>
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11c2 <main+0x62>
mov    $0x1,%ebp
jmp    1244 <main+0xe4>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
lea    0xe4c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rcx
mov    $0x9c,%edi
mov    %ebx,%esi
mov    $0x6,%edx
call   1060 <syscall@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     1204 <main+0xa4>
mov    $0x2,%ebp
jmp    1244 <main+0xe4>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
lea    0xe29(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rcx
mov    $0x9c,%edi
mov    %ebx,%esi
mov    $0x6,%edx
call   1060 <syscall@plt>
mov    $0x3,%ebp
lea    0xe11(%rip),%r14
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x64,%edi
call   1070 <wait@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x64,%edi
call   1070 <wait@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x64,%edi
call   1070 <wait@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x64,%edi
call   1070 <wait@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x64,%edi
call   1070 <wait@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x64,%edi
call   1070 <wait@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x64,%edi
call   1070 <wait@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x64,%edi
call   1070 <wait@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x64,%edi
call   1070 <wait@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x64,%edi
call   1070 <wait@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sched_param = type { i64 }
@.str = [30 x i8] c"before setschedule 1, pid: %d\00"
@.str.1 = [19 x i8] c"before first fork\0A\00"
@.str.2 = [31 x i8] c"before setschedule 2, pid: %d\0A\00"
@.str.3 = [31 x i8] c"before setschedule 3, pid: %d\0A\00"
@.str.4 = [22 x i8] c"before setschedule 3\0A\00"
@.str.5 = [25 x i8] c"\0Anumber %d, process: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sched_param
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %2, i32 0, i32 0
store i64 0, i64* %7
%8 = call i32 (...) @getpid()
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %3
%12 = call i32 @syscall(i32 156, i32 %11, i32 6, %struct.sched_param* %2)
store i32 -1, i32* %4
store i32 1, i32* %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%14 = call i64 (...) @fork()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %36
16: ; preds = %0
%17 = call i32 (...) @getpid()
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %3
%21 = call i32 @syscall(i32 156, i32 %20, i32 6, %struct.sched_param* %2)
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
%24 = call i64 (...) @fork()
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %16
%27 = call i32 (...) @getpid()
store i32 %27, i32* %3
%28 = load i32, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32, i32* %3
%32 = call i32 @syscall(i32 156, i32 %31, i32 6, %struct.sched_param* %2)
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %35
35: ; preds = %26, %16
br label %36
36: ; preds = %35, %0
store i32 0, i32* %6
br label %37
37: ; preds = %45, %36
%38 = load i32, i32* %6
%39 = icmp slt i32 %38, 10
br i1 %39, label %40, label %48
40: ; preds = %37
%41 = load i32, i32* %5
%42 = load i32, i32* %3
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %41, i32 %42)
%44 = call i32 @wait(i32 100)
br label %45
45: ; preds = %40
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %37
48: ; preds = %37
ret i32 0
}

LLVM IR (-O2):
%struct.sched_param = type { i64 }
@.str = [30 x i8] c"before setschedule 1, pid: %d\00"
@.str.2 = [31 x i8] c"before setschedule 2, pid: %d\0A\00"
@.str.3 = [31 x i8] c"before setschedule 3, pid: %d\0A\00"
@.str.5 = [25 x i8] c"\0Anumber %d, process: %d\0A\00"
@str = [18 x i8] c"before first fork\00"
@str.6 = [21 x i8] c"before setschedule 3\00"
define i32 @main() {
%1 = alloca %struct.sched_param
%2 = bitcast %struct.sched_param* %1 to i8*
%3 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %1, i64 0, i32 0
store i64 0, i64* %3
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 @syscall(i32 156, i32 %4, i32 6, %struct.sched_param* %1)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%8 = call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %0
%11 = call i32 (...) @getpid()
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = call i32 @syscall(i32 156, i32 %11, i32 6, %struct.sched_param* %1)
%14 = call i64 (...) @fork()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = call i32 (...) @getpid()
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0))
%20 = call i32 @syscall(i32 156, i32 %17, i32 6, %struct.sched_param* %1)
br label %21
21: ; preds = %10, %16, %0
%22 = phi i32 [ %17, %16 ], [ %11, %10 ], [ %4, %0 ]
%23 = phi i32 [ 3, %16 ], [ 2, %10 ], [ 1, %0 ]
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %23, i32 %22)
%25 = call i32 @wait(i32 100)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %23, i32 %22)
%27 = call i32 @wait(i32 100)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %23, i32 %22)
%29 = call i32 @wait(i32 100)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %23, i32 %22)
%31 = call i32 @wait(i32 100)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %23, i32 %22)
%33 = call i32 @wait(i32 100)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %23, i32 %22)
%35 = call i32 @wait(i32 100)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %23, i32 %22)
%37 = call i32 @wait(i32 100)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %23, i32 %22)
%39 = call i32 @wait(i32 100)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %23, i32 %22)
%41 = call i32 @wait(i32 100)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %23, i32 %22)
%43 = call i32 @wait(i32 100)
ret i32 0
}