#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 */

/* Variables and functions */
int MIN(int, int);
void thread_schedule(int n_x, int threadsPerBlock, int threadIdx_x,
                     int *i_x_for_thread, int *n_x_for_thread) {
  int n_x_per_thread_w;
  int n_x_per_thread_r;
  n_x_per_thread_w = n_x / threadsPerBlock;
  n_x_per_thread_r = n_x % threadsPerBlock;
  *n_x_for_thread = n_x_per_thread_w;
  if (threadIdx_x < n_x_per_thread_r)
    (*n_x_for_thread)++;
  *i_x_for_thread =
      threadIdx_x * n_x_per_thread_w + MIN(threadIdx_x, n_x_per_thread_r);
}


x86 assembly (clang, -O0):
<thread_schedule>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %edx,-0x28(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    115d <thread_schedule+0x4d>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0xc(%rbp),%eax
imul   -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1030 <MIN@plt>
mov    -0x2c(%rbp),%ecx
add    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_schedule>:
push   %rbp
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%ecx
mov    %edi,%eax
cltd
idiv   %esi
mov    %eax,%ebp
xor    %eax,%eax
cmp    %ecx,%edx
setg   %al
add    %ebp,%eax
mov    %eax,(%r8)
imul   %ecx,%ebp
mov    %ecx,%edi
mov    %edx,%esi
call   1030 <MIN@plt>
add    %ebp,%eax
mov    %eax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @thread_schedule(i32 %0, i32 %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%13 = load i32, i32* %6
%14 = load i32, i32* %7
%15 = sdiv i32 %13, %14
store i32 %15, i32* %11
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = srem i32 %16, %17
store i32 %18, i32* %12
%19 = load i32, i32* %11
%20 = load i32*, i32** %10
store i32 %19, i32* %20
%21 = load i32, i32* %8
%22 = load i32, i32* %12
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %28
24: ; preds = %5
%25 = load i32*, i32** %10
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1
store i32 %27, i32* %25
br label %28
28: ; preds = %24, %5
%29 = load i32, i32* %8
%30 = load i32, i32* %11
%31 = mul nsw i32 %29, %30
%32 = load i32, i32* %8
%33 = load i32, i32* %12
%34 = call i32 @MIN(i32 %32, i32 %33)
%35 = add nsw i32 %31, %34
%36 = load i32*, i32** %9
store i32 %35, i32* %36
ret void
}

LLVM IR (-O2):
define void @thread_schedule(i32 %0, i32 %1, i32 %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4) {
%6 = sdiv i32 %0, %1
%7 = srem i32 %0, %1
%8 = icmp sgt i32 %7, %2
%9 = zext i1 %8 to i32
%10 = add nsw i32 %6, %9
store i32 %10, i32* %4
%11 = mul nsw i32 %6, %2
%12 = tail call i32 @MIN(i32 %2, i32 %7)
%13 = add nsw i32 %12, %11
store i32 %13, i32* %3
ret void
}