#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 uint32_t;

/* Variables and functions */
int rand();
void f2m_rand(uint32_t t, uint32_t m, uint32_t *A) {
  uint32_t i;
  for (i = 0; i < t - 1; i++)
    A[i] = rand();
  A[t - 1] = rand() & (0xFFFFFFFF >> (32 - m % 32));
}


x86 assembly (clang, -O0):
<f2m_rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    115c <f2m_rand+0x4c>
mov    $0x0,%al
call   1030 <rand@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <f2m_rand+0x19>
mov    $0x0,%al
call   1030 <rand@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    -0x18(%rbp),%edx
mov    $0x20,%ecx
sub    %eax,%ecx
mov    $0xffffffff,%eax
shr    %cl,%eax
and    %eax,%edx
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f2m_rand>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %esi,%r14d
lea    -0x1(%rdi),%r15d
cmp    $0x2,%edi
jl     1144 <f2m_rand+0x34>
mov    %r15d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <rand@plt>
mov    %eax,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1130 <f2m_rand+0x20>
xor    %eax,%eax
call   1030 <rand@plt>
lea    0x1f(%r14),%ecx
test   %r14d,%r14d
cmovns %r14d,%ecx
and    $0xe0,%ecx
sub    %ecx,%r14d
neg    %r14b
mov    %r14d,%ecx
shl    %cl,%eax
shr    %cl,%eax
movslq %r15d,%rcx
mov    %eax,(%r12,%rcx,4)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @f2m_rand(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
br label %8
8: ; preds = %19, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %22
13: ; preds = %8
%14 = call i32 (...) @rand()
%15 = load i32*, i32** %6
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
store i32 %14, i32* %18
br label %19
19: ; preds = %13
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
store i32 %21, i32* %7
br label %8
22: ; preds = %8
%23 = call i32 (...) @rand()
%24 = load i32, i32* %5
%25 = srem i32 %24, 32
%26 = sub nsw i32 32, %25
%27 = lshr i32 -1, %26
%28 = and i32 %23, %27
%29 = load i32*, i32** %6
%30 = load i32, i32* %4
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %29, i64 %32
store i32 %28, i32* %33
ret void
}

LLVM IR (-O2):
define void @f2m_rand(i32 %0, i32 %1, i32* nocapture writeonly %2) {
%4 = add i32 %0, -1
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %14
6: ; preds = %3
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %12, %8 ]
%10 = tail call i32 (...) @rand()
%11 = getelementptr inbounds i32, i32* %2, i64 %9
store i32 %10, i32* %11
%12 = add nuw nsw i64 %9, 1
%13 = icmp eq i64 %12, %7
br i1 %13, label %14, label %8
14: ; preds = %8, %3
%15 = tail call i32 (...) @rand()
%16 = srem i32 %1, 32
%17 = sub nsw i32 32, %16
%18 = lshr i32 -1, %17
%19 = and i32 %15, %18
%20 = sext i32 %4 to i64
%21 = getelementptr inbounds i32, i32* %2, i64 %20
store i32 %19, i32* %21
ret void
}