#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 int /*<<< orphan*/ nr_cores;
typedef int /*<<< orphan*/ cores;
typedef int /*<<< orphan*/ action;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int get_socket(int);
int /*<<< orphan*/ perror(char *);
int send(int, int *, int, int /*<<< orphan*/);
int change_cores(int pid, int nr_cores, int *cores) {
  int s = get_socket(pid);
  if (s < 0)
    return s;
  int action = 1;
  if (send(s, &action, sizeof(action), 0) == -1) {
    perror("send");
    return -2;
  }
  if (send(s, &nr_cores, sizeof(nr_cores), 0) == -1) {
    perror("send");
    return -2;
  }
  int i;
  for (i = 0; i < nr_cores; i++) {
    if (send(s, &(cores[i]), sizeof(cores[i]), 0) == -1) {
      perror("send");
      return -3;
    }
  }
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<change_cores>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <get_socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1172 <change_cores+0x32>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1255 <change_cores+0x115>
movl   $0x1,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
jne    11ad <change_cores+0x6d>
lea    0xe64(%rip),%rdi
call   1060 <perror@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1255 <change_cores+0x115>
mov    -0x1c(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
jne    11e1 <change_cores+0xa1>
lea    0xe30(%rip),%rdi
call   1060 <perror@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1255 <change_cores+0x115>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1246 <change_cores+0x106>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
jne    1233 <change_cores+0xf3>
lea    0xdde(%rip),%rdi
call   1060 <perror@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1255 <change_cores+0x115>
jmp    1238 <change_cores+0xf8>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e8 <change_cores+0xa8>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_cores>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %esi,0x8(%rsp)
call   1030 <get_socket@plt>
mov    %eax,%r14d
test   %eax,%eax
js     11d4 <change_cores+0x94>
movl   $0x1,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %r14d,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     11e0 <change_cores+0xa0>
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     11e0 <change_cores+0xa0>
cmpl   $0x0,0x8(%rsp)
jle    11c9 <change_cores+0x89>
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     11f4 <change_cores+0xb4>
add    $0x1,%rbp
movslq 0x8(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%rbp
jl     11a0 <change_cores+0x60>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe19(%rip),%rdi
call   1060 <perror@plt>
mov    $0xfffffffe,%r14d
jmp    11d4 <change_cores+0x94>
lea    0xe05(%rip),%rdi
call   1060 <perror@plt>
mov    $0xfffffffd,%r14d
jmp    11d4 <change_cores+0x94>

LLVM IR (-O0):
@.str = [5 x i8] c"send\00"
define i32 @change_cores(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%11 = load i32, i32* %5
%12 = call i32 @get_socket(i32 %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* %8
store i32 %16, i32* %4
br label %51
17: ; preds = %3
store i32 1, i32* %9
%18 = load i32, i32* %8
%19 = call i32 @send(i32 %18, i32* %9, i32 4, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -2, i32* %4
br label %51
23: ; preds = %17
%24 = load i32, i32* %8
%25 = call i32 @send(i32 %24, i32* %6, i32 4, i32 0)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -2, i32* %4
br label %51
29: ; preds = %23
store i32 0, i32* %10
br label %30
30: ; preds = %45, %29
%31 = load i32, i32* %10
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %48
34: ; preds = %30
%35 = load i32, i32* %8
%36 = load i32*, i32** %7
%37 = load i32, i32* %10
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = call i32 @send(i32 %35, i32* %39, i32 4, i32 0)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %34
%43 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -3, i32* %4
br label %51
44: ; preds = %34
br label %45
45: ; preds = %44
%46 = load i32, i32* %10
%47 = add nsw i32 %46, 1
store i32 %47, i32* %10
br label %30
48: ; preds = %30
%49 = load i32, i32* %8
%50 = call i32 @close(i32 %49)
store i32 0, i32* %4
br label %51
51: ; preds = %48, %42, %27, %21, %15
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
@.str = [5 x i8] c"send\00"
define i32 @change_cores(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
store i32 %1, i32* %4
%6 = tail call i32 @get_socket(i32 %0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %38, label %8
8: ; preds = %3
%9 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%10 = call i32 @send(i32 %6, i32* %5, i32 4, i32 0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %36
14: ; preds = %8
%15 = call i32 @send(i32 %6, i32* %4, i32 4, i32 0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 0
br i1 %19, label %26, label %34
20: ; preds = %14
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %36
22: ; preds = %26
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %31, %24
br i1 %25, label %26, label %34
26: ; preds = %17, %22
%27 = phi i64 [ %31, %22 ], [ 0, %17 ]
%28 = getelementptr inbounds i32, i32* %2, i64 %27
%29 = call i32 @send(i32 %6, i32* %28, i32 4, i32 0)
%30 = icmp eq i32 %29, -1
%31 = add nuw nsw i64 %27, 1
br i1 %30, label %32, label %22
32: ; preds = %26
%33 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %36
34: ; preds = %22, %17
%35 = call i32 @close(i32 %6)
br label %36
36: ; preds = %32, %34, %20, %12
%37 = phi i32 [ -2, %12 ], [ -2, %20 ], [ -3, %32 ], [ 0, %34 ]
br label %38
38: ; preds = %3, %36
%39 = phi i32 [ %37, %36 ], [ %6, %3 ]
ret i32 %39
}