#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 scalar_t__ int32_t;

/* Variables and functions */
scalar_t__ INT_MAX;
int /*<<< orphan*/ _SC_NPROCESSORS_ONLN;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__, scalar_t__,
                           ...);
int /*<<< orphan*/ stderr;
scalar_t__ sysconf(int /*<<< orphan*/);
int32_t dup_set_affinity(int32_t num_queues, int32_t *abegin, int32_t *aend) {
  int32_t ncpus = sysconf(_SC_NPROCESSORS_ONLN);
  if (*abegin < 0 || *aend < 0) {
    do {
      fprintf(stderr,
              "Error: "
              "Invalid affinity range %d to %d."
              "\n",
              *abegin, *aend);
      fflush(stderr);
    } while (0);
    return 1;
  }
  if (num_queues > ncpus) {
    do {
      fprintf(stderr,
              "Error: "
              "The number of queues is %d but system only have %d CPU(s)."
              "\n",
              num_queues, ncpus);
      fflush(stderr);
    } while (0);
    return 1;
  }
  if (*aend == INT_MAX) {
    *aend = *abegin + num_queues - 1;
  }
  if (*aend >= ncpus) {
    do {
      fprintf(stderr,
              "Error: "
              "Invalid affinity range %d to %d, system only have %d CPU(s)."
              "\n",
              *abegin, *aend, ncpus);
      fflush(stderr);
    } while (0);
    return 1;
  }
  if (num_queues > (*aend - *abegin + 1)) {
    do {
      fprintf(stderr,
              "Error: "
              "Invalid affinity range %d to %d when the number of queue is %d."
              "\n",
              *abegin, *aend, num_queues);
      fflush(stderr);
    } while (0);
    return 1;
  } else {
    *aend = *abegin + num_queues - 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<dup_set_affinity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jl     1172 <dup_set_affinity+0x42>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jge    11b7 <dup_set_affinity+0x87>
jmp    1177 <dup_set_affinity+0x47>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
movq   $0x1,-0x8(%rbp)
jmp    1311 <dup_set_affinity+0x1e1>
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
jle    1204 <dup_set_affinity+0xd4>
jmp    11ca <dup_set_affinity+0x9a>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
movq   $0x1,-0x8(%rbp)
jmp    1311 <dup_set_affinity+0x1e1>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2dce(%rip),%rcx
cmp    (%rcx),%rax
jne    1231 <dup_set_affinity+0x101>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    -0x10(%rbp),%rcx
sub    $0x1,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
cmp    -0x28(%rbp),%rax
jl     128b <dup_set_affinity+0x15b>
jmp    1247 <dup_set_affinity+0x117>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
mov    -0x28(%rbp),%r8
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
movq   $0x1,-0x8(%rbp)
jmp    1311 <dup_set_affinity+0x1e1>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rcx
mov    -0x18(%rbp),%rdx
sub    (%rdx),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jle    12f3 <dup_set_affinity+0x1c3>
jmp    12af <dup_set_affinity+0x17f>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%r8
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
movq   $0x1,-0x8(%rbp)
jmp    1311 <dup_set_affinity+0x1e1>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    -0x10(%rbp),%rcx
sub    $0x1,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dup_set_affinity>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    (%rbx),%rdx
mov    (%r15),%rcx
test   %rdx,%rdx
js     1179 <dup_set_affinity+0x49>
test   %rcx,%rcx
js     1179 <dup_set_affinity+0x49>
cmp    %r14,%rax
jge    11a2 <dup_set_affinity+0x72>
mov    0x2e68(%rip),%rbx
mov    (%rbx),%edi
lea    0xeb8(%rip),%rsi
mov    %r14,%rdx
mov    %rax,%rcx
jmp    1189 <dup_set_affinity+0x59>
mov    0x2e50(%rip),%rbx
mov    (%rbx),%edi
lea    0xe77(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%rbx),%edi
call   1040 <fflush@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e37(%rip),%rsi
cmp    (%rsi),%rcx
jne    11b9 <dup_set_affinity+0x89>
lea    (%r14,%rdx,1),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,(%r15)
cmp    %rax,%rcx
jge    11ec <dup_set_affinity+0xbc>
mov    (%rbx),%rdx
mov    %rcx,%rax
sub    %rdx,%rax
add    $0x1,%rax
cmp    %r14,%rax
jge    120f <dup_set_affinity+0xdf>
mov    0x2df9(%rip),%rbx
mov    (%rbx),%edi
lea    0xed1(%rip),%rsi
mov    %r14,%r8
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1190 <dup_set_affinity+0x60>
mov    0x2ddd(%rip),%r14
mov    (%r14),%edi
mov    (%rbx),%rdx
lea    0xe6c(%rip),%rsi
mov    %rax,%r8
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
jmp    1192 <dup_set_affinity+0x62>
lea    (%r14,%rdx,1),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,(%r15)
xor    %eax,%eax
jmp    119c <dup_set_affinity+0x6c>

LLVM IR (-O0):
@_SC_NPROCESSORS_ONLN = global i32 0
@stderr = global i32 0
@.str = [41 x i8] c"Error: Invalid affinity range %d to %d.\0A\00"
@.str.1 = [67 x i8] c"Error: The number of queues is %d but system only have %d CPU(s).\0A\00"
@INT_MAX = global i64 0
@.str.2 = [69 x i8] c"Error: Invalid affinity range %d to %d, system only have %d CPU(s).\0A\00"
@.str.3 = [72 x i8] c"Error: Invalid affinity range %d to %d when the number of queue is %d.\0A\00"
define i64 @dup_set_affinity(i64 %0, i64* %1, i64* %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i64
store i64 %0, i64* %5
store i64* %1, i64** %6
store i64* %2, i64** %7
%9 = load i32, i32* @_SC_NPROCESSORS_ONLN
%10 = call i64 @sysconf(i32 %9)
store i64 %10, i64* %8
%11 = load i64*, i64** %6
%12 = load i64, i64* %11
%13 = icmp slt i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %3
%15 = load i64*, i64** %7
%16 = load i64, i64* %15
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %14, %3
br label %19
19: ; preds = %18
%20 = load i32, i32* @stderr
%21 = load i64*, i64** %6
%22 = load i64, i64* %21
%23 = load i64*, i64** %7
%24 = load i64, i64* %23
%25 = call i32 (i32, i8*, i64, i64, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i64 %22, i64 %24)
%26 = load i32, i32* @stderr
%27 = call i32 @fflush(i32 %26)
br label %28
28: ; preds = %19
store i64 1, i64* %4
br label %100
29: ; preds = %14
%30 = load i64, i64* %5
%31 = load i64, i64* %8
%32 = icmp sgt i64 %30, %31
br i1 %32, label %33, label %42
33: ; preds = %29
br label %34
34: ; preds = %33
%35 = load i32, i32* @stderr
%36 = load i64, i64* %5
%37 = load i64, i64* %8
%38 = call i32 (i32, i8*, i64, i64, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i64 %36, i64 %37)
%39 = load i32, i32* @stderr
%40 = call i32 @fflush(i32 %39)
br label %41
41: ; preds = %34
store i64 1, i64* %4
br label %100
42: ; preds = %29
%43 = load i64*, i64** %7
%44 = load i64, i64* %43
%45 = load i64, i64* @INT_MAX
%46 = icmp eq i64 %44, %45
br i1 %46, label %47, label %54
47: ; preds = %42
%48 = load i64*, i64** %6
%49 = load i64, i64* %48
%50 = load i64, i64* %5
%51 = add nsw i64 %49, %50
%52 = sub nsw i64 %51, 1
%53 = load i64*, i64** %7
store i64 %52, i64* %53
br label %54
54: ; preds = %47, %42
%55 = load i64*, i64** %7
%56 = load i64, i64* %55
%57 = load i64, i64* %8
%58 = icmp sge i64 %56, %57
br i1 %58, label %59, label %71
59: ; preds = %54
br label %60
60: ; preds = %59
%61 = load i32, i32* @stderr
%62 = load i64*, i64** %6
%63 = load i64, i64* %62
%64 = load i64*, i64** %7
%65 = load i64, i64* %64
%66 = load i64, i64* %8
%67 = call i32 (i32, i8*, i64, i64, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0), i64 %63, i64 %65, i64 %66)
%68 = load i32, i32* @stderr
%69 = call i32 @fflush(i32 %68)
br label %70
70: ; preds = %60
store i64 1, i64* %4
br label %100
71: ; preds = %54
%72 = load i64, i64* %5
%73 = load i64*, i64** %7
%74 = load i64, i64* %73
%75 = load i64*, i64** %6
%76 = load i64, i64* %75
%77 = sub nsw i64 %74, %76
%78 = add nsw i64 %77, 1
%79 = icmp sgt i64 %72, %78
br i1 %79, label %80, label %92
80: ; preds = %71
br label %81
81: ; preds = %80
%82 = load i32, i32* @stderr
%83 = load i64*, i64** %6
%84 = load i64, i64* %83
%85 = load i64*, i64** %7
%86 = load i64, i64* %85
%87 = load i64, i64* %5
%88 = call i32 (i32, i8*, i64, i64, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0), i64 %84, i64 %86, i64 %87)
%89 = load i32, i32* @stderr
%90 = call i32 @fflush(i32 %89)
br label %91
91: ; preds = %81
store i64 1, i64* %4
br label %100
92: ; preds = %71
%93 = load i64*, i64** %6
%94 = load i64, i64* %93
%95 = load i64, i64* %5
%96 = add nsw i64 %94, %95
%97 = sub nsw i64 %96, 1
%98 = load i64*, i64** %7
store i64 %97, i64* %98
br label %99
99: ; preds = %92
store i64 0, i64* %4
br label %100
100: ; preds = %99, %91, %70, %41, %28
%101 = load i64, i64* %4
ret i64 %101
}

LLVM IR (-O2):
@_SC_NPROCESSORS_ONLN = global i32 0
@stderr = global i32 0
@.str = [41 x i8] c"Error: Invalid affinity range %d to %d.\0A\00"
@.str.1 = [67 x i8] c"Error: The number of queues is %d but system only have %d CPU(s).\0A\00"
@INT_MAX = global i64 0
@.str.2 = [69 x i8] c"Error: Invalid affinity range %d to %d, system only have %d CPU(s).\0A\00"
@.str.3 = [72 x i8] c"Error: Invalid affinity range %d to %d when the number of queue is %d.\0A\00"
define i64 @dup_set_affinity(i64 %0, i64* nocapture %1, i64* nocapture %2) {
%4 = load i32, i32* @_SC_NPROCESSORS_ONLN
%5 = tail call i64 @sysconf(i32 %4)
%6 = load i64, i64* %1
%7 = icmp slt i64 %6, 0
%8 = load i64, i64* %2
%9 = icmp slt i64 %8, 0
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %11, label %16
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, i64, i64, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i64 %6, i64 %8)
%14 = load i32, i32* @stderr
%15 = tail call i32 @fflush(i32 %14)
br label %51
16: ; preds = %3
%17 = icmp slt i64 %5, %0
br i1 %17, label %18, label %23
18: ; preds = %16
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, i64, i64, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i64 %0, i64 %5)
%21 = load i32, i32* @stderr
%22 = tail call i32 @fflush(i32 %21)
br label %51
23: ; preds = %16
%24 = load i64, i64* @INT_MAX
%25 = icmp eq i64 %8, %24
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = add i64 %0, -1
%28 = add i64 %27, %6
store i64 %28, i64* %2
br label %29
29: ; preds = %26, %23
%30 = phi i64 [ %28, %26 ], [ %8, %23 ]
%31 = icmp slt i64 %30, %5
br i1 %31, label %38, label %32
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = load i64, i64* %1
%35 = tail call i32 (i32, i8*, i64, i64, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0), i64 %34, i64 %30, i64 %5)
%36 = load i32, i32* @stderr
%37 = tail call i32 @fflush(i32 %36)
br label %51
38: ; preds = %29
%39 = load i64, i64* %1
%40 = add nsw i64 %30, 1
%41 = sub i64 %40, %39
%42 = icmp slt i64 %41, %0
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = load i32, i32* @stderr
%45 = tail call i32 (i32, i8*, i64, i64, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0), i64 %39, i64 %30, i64 %0)
%46 = load i32, i32* @stderr
%47 = tail call i32 @fflush(i32 %46)
br label %51
48: ; preds = %38
%49 = add i64 %0, -1
%50 = add i64 %49, %39
store i64 %50, i64* %2
br label %51
51: ; preds = %48, %43, %32, %18, %11
%52 = phi i64 [ 1, %11 ], [ 1, %18 ], [ 1, %32 ], [ 1, %43 ], [ 0, %48 ]
ret i64 %52
}