#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;
};
typedef int /*<<< orphan*/ cpu_set_t;

/* Variables and functions */
int /*<<< orphan*/ CPU_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ printDots(int);
int /*<<< orphan*/ printWithStatus(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ pthread_self();
int pthread_setschedparam(int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sched_param *);
int sched_setaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int setCpuParams(int cpuCore, int priority) {
  int err = 0;
  cpu_set_t cpu;
  struct sched_param params;
  char printStr[128], temp[16];
  if (!err) {
    CPU_ZERO(&cpu);
    CPU_SET(cpuCore, &cpu);
    err = sched_setaffinity(0, sizeof(cpu_set_t), &cpu);
    printStr[0] = '\0';
    strcat(printStr, "Setting CPU Affinity to CPU");
    sprintf(temp, "%d", cpuCore);
    strcat(printStr, temp);
    printf("%s", printStr);
    if (strlen(printStr) < 70)
      printDots(70 - strlen(printStr));
    printWithStatus("", err);
    printf("\n");
  }
  if (!err) {
    params.sched_priority = priority;
    err = pthread_setschedparam(pthread_self(), SCHED_FIFO, &params);
    printStr[0] = '\0';
    strcat(printStr, "Setting thread priority to ");
    sprintf(temp, "%d", priority);
    strcat(printStr, temp);
    printf("%s", printStr);
    if (strlen(printStr) < 70)
      printDots(70 - strlen(printStr));
    printWithStatus("", err);
    printf("\n");
  }
  return err;
}


x86 assembly (clang, -O0):
<setCpuParams>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    129c <setCpuParams+0xec>
lea    -0x10(%rbp),%rdi
call   1090 <CPU_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   10d0 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x10(%rbp),%rdx
call   1080 <sched_setaffinity@plt>
mov    %eax,-0xc(%rbp)
movb   $0x0,-0xa0(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xdf7(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   10b0 <strcat@plt>
lea    -0xa0(%rbp),%rsi
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xa0(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x46,%eax
jge    127f <setCpuParams+0xcf>
lea    -0xa0(%rbp),%rdi
call   1060 <strlen@plt>
mov    $0x46,%edi
sub    %eax,%edi
call   1040 <printDots@plt>
mov    -0xc(%rbp),%esi
lea    0xd9a(%rip),%rdi
call   1030 <printWithStatus@plt>
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
jne    136c <setCpuParams+0x1bc>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   10a0 <pthread_self@plt>
mov    %eax,%edi
mov    0x2d2c(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <pthread_setschedparam@plt>
mov    %eax,-0xc(%rbp)
movb   $0x0,-0xa0(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xd45(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xd27(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   10b0 <strcat@plt>
lea    -0xa0(%rbp),%rsi
lea    0xd04(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xa0(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x46,%eax
jge    134f <setCpuParams+0x19f>
lea    -0xa0(%rbp),%rdi
call   1060 <strlen@plt>
mov    $0x46,%edi
sub    %eax,%edi
call   1040 <printDots@plt>
mov    -0xc(%rbp),%esi
lea    0xcca(%rip),%rdi
call   1030 <printWithStatus@plt>
lea    0xcbd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setCpuParams>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa0,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <CPU_ZERO@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   10e0 <CPU_SET@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1090 <sched_setaffinity@plt>
mov    %eax,%r15d
movb   $0x0,0x20(%rsp)
lea    0xdf7(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   10c0 <strcat@plt>
lea    0xdff(%rip),%rsi
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %ebp,%edx
call   10d0 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10c0 <strcat@plt>
lea    0xde1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
cmp    $0x45,%eax
jg     126b <setCpuParams+0xab>
lea    0x20(%rsp),%rdi
call   1070 <strlen@plt>
mov    $0x46,%edi
sub    %eax,%edi
call   1050 <printDots@plt>
lea    0xdcb(%rip),%rdi
mov    %r15d,%esi
call   1040 <printWithStatus@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r15d,%r15d
jne    1339 <setCpuParams+0x179>
mov    %r14d,0x8(%rsp)
xor    %eax,%eax
call   10b0 <pthread_self@plt>
mov    0x2d48(%rip),%rcx
mov    (%rcx),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1060 <pthread_setschedparam@plt>
mov    %eax,%r15d
movb   $0x0,0x20(%rsp)
lea    0xd65(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   10c0 <strcat@plt>
lea    0xd4b(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14d,%edx
call   10d0 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10c0 <strcat@plt>
lea    0xd2c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
cmp    $0x45,%eax
jg     1320 <setCpuParams+0x160>
lea    0x20(%rsp),%rdi
call   1070 <strlen@plt>
mov    $0x46,%edi
sub    %eax,%edi
call   1050 <printDots@plt>
lea    0xd16(%rip),%rdi
mov    %r15d,%esi
call   1040 <printWithStatus@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15d,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@.str = [28 x i8] c"Setting CPU Affinity to CPU\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [2 x i8] c"\0A\00"
@SCHED_FIFO = global i32 0
@.str.5 = [28 x i8] c"Setting thread priority to \00"
define i32 @setCpuParams(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sched_param
%8 = alloca [128 x i8]
%9 = alloca [16 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %40, label %12
12: ; preds = %2
%13 = call i32 @CPU_ZERO(i32* %6)
%14 = load i32, i32* %3
%15 = call i32 @CPU_SET(i32 %14, i32* %6)
%16 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %6)
store i32 %16, i32* %5
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
store i8 0, i8* %17
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%19 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%21 = load i32, i32* %3
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%25 = call i32 @strcat(i8* %23, i8* %24)
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = icmp slt i32 %29, 70
br i1 %30, label %31, label %36
31: ; preds = %12
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = sub nsw i32 70, %33
%35 = call i32 @printDots(i32 %34)
br label %36
36: ; preds = %31, %12
%37 = load i32, i32* %5
%38 = call i32 @printWithStatus(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %36, %2
%41 = load i32, i32* %5
%42 = icmp ne i32 %41, 0
br i1 %42, label %72, label %43
43: ; preds = %40
%44 = load i32, i32* %4
%45 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %7, i32 0, i32 0
store i32 %44, i32* %45
%46 = call i32 (...) @pthread_self()
%47 = load i32, i32* @SCHED_FIFO
%48 = call i32 @pthread_setschedparam(i32 %46, i32 %47, %struct.sched_param* %7)
store i32 %48, i32* %5
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
store i8 0, i8* %49
%50 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%51 = call i32 @strcat(i8* %50, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%52 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%53 = load i32, i32* %4
%54 = call i32 @sprintf(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %53)
%55 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%56 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%57 = call i32 @strcat(i8* %55, i8* %56)
%58 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %58)
%60 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%61 = call i32 @strlen(i8* %60)
%62 = icmp slt i32 %61, 70
br i1 %62, label %63, label %68
63: ; preds = %43
%64 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%65 = call i32 @strlen(i8* %64)
%66 = sub nsw i32 70, %65
%67 = call i32 @printDots(i32 %66)
br label %68
68: ; preds = %63, %43
%69 = load i32, i32* %5
%70 = call i32 @printWithStatus(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 %69)
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %72
72: ; preds = %68, %40
%73 = load i32, i32* %5
ret i32 %73
}

LLVM IR (-O2):
%struct.sched_param = type { i32 }
@.str = [28 x i8] c"Setting CPU Affinity to CPU\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [1 x i8] zeroinitializer
@SCHED_FIFO = global i32 0
@.str.5 = [28 x i8] c"Setting thread priority to \00"
define i32 @setCpuParams(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.sched_param
%5 = alloca [128 x i8]
%6 = alloca [16 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sched_param* %4 to i8*
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%11 = call i32 @CPU_ZERO(i32* %3)
%12 = call i32 @CPU_SET(i32 %0, i32* %3)
%13 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %3)
store i8 0, i8* %9
%14 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%16 = call i32 @strcat(i8* %9, i8* %10)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%18 = call i32 @strlen(i8* %9)
%19 = icmp slt i32 %18, 70
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = call i32 @strlen(i8* %9)
%22 = sub nsw i32 70, %21
%23 = call i32 @printDots(i32 %22)
br label %24
24: ; preds = %20, %2
%25 = call i32 @printWithStatus(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%26 = call i32 @putchar(i32 10)
%27 = icmp eq i32 %13, 0
br i1 %27, label %28, label %46
28: ; preds = %24
%29 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %4, i64 0, i32 0
store i32 %1, i32* %29
%30 = call i32 (...) @pthread_self()
%31 = load i32, i32* @SCHED_FIFO
%32 = call i32 @pthread_setschedparam(i32 %30, i32 %31, %struct.sched_param* %4)
store i8 0, i8* %9
%33 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%34 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%35 = call i32 @strcat(i8* %9, i8* %10)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%37 = call i32 @strlen(i8* %9)
%38 = icmp slt i32 %37, 70
br i1 %38, label %39, label %43
39: ; preds = %28
%40 = call i32 @strlen(i8* %9)
%41 = sub nsw i32 70, %40
%42 = call i32 @printDots(i32 %41)
br label %43
43: ; preds = %39, %28
%44 = call i32 @printWithStatus(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%45 = call i32 @putchar(i32 10)
br label %46
46: ; preds = %43, %24
%47 = phi i32 [ %13, %24 ], [ %32, %43 ]
ret i32 %47
}