void test(x, npoints, thds) int x[];
int npoints, thds;
{
  int iam, ipoints;
  printf("set thread = %d\n", thds);
  omp_set_dynamic(0);
  omp_set_num_threads(thds);
#pragma omp parallel shared(x, npoints) private(iam, ipoints)
  {
    if (omp_get_num_threads() != thds)
      abort();
    iam = omp_get_thread_num();
    ipoints = npoints / thds;
    do_by_x(x, iam, ipoints);
  }
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
mov    $0x0,%al
call   1070 <omp_set_dynamic@plt>
mov    -0x10(%rbp),%edi
mov    $0x0,%al
call   1080 <omp_set_num_threads@plt>
mov    $0x0,%al
call   1060 <omp_get_num_threads@plt>
cmp    -0x10(%rbp),%eax
je     11bb <test+0x4b>
call   1030 <abort@plt>
mov    $0x0,%al
call   1040 <omp_get_thread_num@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    $0x0,%al
call   1090 <do_by_x@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xe7e(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
xor    %eax,%eax
call   1070 <omp_set_dynamic@plt>
mov    %ebp,%edi
xor    %eax,%eax
call   1080 <omp_set_num_threads@plt>
xor    %eax,%eax
call   1060 <omp_get_num_threads@plt>
cmp    %ebp,%eax
jne    11c6 <test+0x56>
xor    %eax,%eax
call   1040 <omp_get_thread_num@plt>
mov    %eax,%esi
mov    %ebx,%eax
cltd
idiv   %ebp
mov    %r14,%rdi
mov    %eax,%edx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1090 <do_by_x@plt>
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"set thread = %d\0A\00"
define void @test(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 (i32, ...) bitcast (i32 (...)* @omp_set_dynamic to i32 (i32, ...)*)(i32 0)
%12 = load i32, i32* %6
%13 = call i32 (i32, ...) bitcast (i32 (...)* @omp_set_num_threads to i32 (i32, ...)*)(i32 %12)
%14 = call i32 (...) @omp_get_num_threads()
%15 = load i32, i32* %6
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %3
unreachable
18: ; preds = %3
%19 = call i32 (...) @omp_get_thread_num()
store i32 %19, i32* %7
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = sdiv i32 %20, %21
store i32 %22, i32* %8
%23 = load i32*, i32** %4
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = call i32 (i32*, i32, i32, ...) bitcast (i32 (...)* @do_by_x to i32 (i32*, i32, i32, ...)*)(i32* %23, i32 %24, i32 %25)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"set thread = %d\0A\00"
define void @test(i32* %0, i32 %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %2)
%5 = tail call i32 (i32, ...) bitcast (i32 (...)* @omp_set_dynamic to i32 (i32, ...)*)(i32 0)
%6 = tail call i32 (i32, ...) bitcast (i32 (...)* @omp_set_num_threads to i32 (i32, ...)*)(i32 %2)
%7 = tail call i32 (...) @omp_get_num_threads()
%8 = icmp eq i32 %7, %2
br i1 %8, label %10, label %9
9: ; preds = %3
tail call void @abort()
unreachable
10: ; preds = %3
%11 = tail call i32 (...) @omp_get_thread_num()
%12 = sdiv i32 %1, %2
%13 = tail call i32 (i32*, i32, i32, ...) bitcast (i32 (...)* @do_by_x to i32 (i32*, i32, i32, ...)*)(i32* %0, i32 %11, i32 %12)
ret void
}