#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 {
  int sched_priority;
};

/* Variables and functions */
int /*<<< orphan*/ SCHED_RR;
int atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sched_setscheduler(int /*<<< orphan*/, int /*<<< orphan*/,
                                      struct sched_param *);
int main(int argc, char **argv) {
  printf("Setting SCHED_RR and priority to %d\n", atoi(argv[1]));
  struct sched_param param;
  param.sched_priority = atoi(argv[1]);
  sched_setscheduler(0, SCHED_RR, &param);
  int n = 0;
  while (1) {
    n = n + 1;
    if (!(n % 10000000)) {
      printf("Inst:%s RR Prio %d running (n=%d)\n", argv[2], atoi(argv[1]), n);
    }
  }
}


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    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x18(%rbp),%rdx
call   1040 <sched_setscheduler@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x989680,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11db <main+0xab>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
mov    -0x1c(%rbp),%ecx
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118e <main+0x5e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
lea    0xeb1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%r15),%rdi
call   1050 <atoi@plt>
mov    %eax,0x8(%rsp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1040 <sched_setscheduler@plt>
mov    $0xffffffff,%ebx
mov    $0x1,%ebp
lea    0xe9a(%rip),%r14
jmp    1196 <main+0x66>
nopl   (%rax)
add    $0xffffffff,%ebx
add    $0x1,%ebp
mov    %ebp,%eax
imul   $0x6b5fca6b,%rax,%rax
shr    $0x36,%rax
imul   $0x989680,%eax,%eax
add    %ebx,%eax
jne    1190 <main+0x60>
mov    0x8(%r15),%rdi
mov    0x10(%r15),%r12
call   1050 <atoi@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %eax,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1190 <main+0x60>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [37 x i8] c"Setting SCHED_RR and priority to %d\0A\00"
@SCHED_RR = global i32 0
@.str.1 = [35 x i8] c"Inst:%s RR Prio %d running (n=%d)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sched_param
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @atoi(i8* %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
%17 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %6, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* @SCHED_RR
%19 = call i32 @sched_setscheduler(i32 0, i32 %18, %struct.sched_param* %6)
store i32 0, i32* %7
br label %20
20: ; preds = %2, %36
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = srem i32 %23, 10000000
%25 = icmp ne i32 %24, 0
br i1 %25, label %36, label %26
26: ; preds = %20
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
%34 = load i32, i32* %7
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %29, i32 %33, i32 %34)
br label %36
36: ; preds = %26, %20
br label %20
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@.str = [37 x i8] c"Setting SCHED_RR and priority to %d\0A\00"
@SCHED_RR = global i32 0
@.str.1 = [35 x i8] c"Inst:%s RR Prio %d running (n=%d)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sched_param
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32 @atoi(i8* %5)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = bitcast %struct.sched_param* %3 to i8*
%9 = load i8*, i8** %4
%10 = tail call i32 @atoi(i8* %9)
%11 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %3, i64 0, i32 0
store i32 %10, i32* %11
%12 = load i32, i32* @SCHED_RR
%13 = call i32 @sched_setscheduler(i32 0, i32 %12, %struct.sched_param* %3)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
br label %15
15: ; preds = %25, %2
%16 = phi i32 [ 0, %2 ], [ %17, %25 ]
%17 = add nuw nsw i32 %16, 1
%18 = urem i32 %17, 10000000
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i8*, i8** %14
%22 = load i8*, i8** %4
%23 = call i32 @atoi(i8* %22)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %23, i32 %17)
br label %25
25: ; preds = %20, %15
br label %15
}