#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 /*<<< orphan*/ free(char *);
int lrand48();
char *malloc(int);
char *rndalpha(int n, int m) {
  int i;
  char *ret = malloc(n + 1);
  if (ret) {
    for (i = 0; i < n; i++) {
      ret[i] = 'a' + lrand48() % m;
    }
    ret[n] = 0;
  }
  free(ret);
  return ret;
}


x86 assembly (clang, -O0):
<rndalpha>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119e <rndalpha+0x6e>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1192 <rndalpha+0x62>
mov    $0x0,%al
call   1050 <lrand48@plt>
cltd
idivl  -0x8(%rbp)
add    $0x61,%edx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115f <rndalpha+0x2f>
mov    -0x18(%rbp),%rax
movslq -0x4(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rndalpha>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
lea    0x1(%r14),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     1183 <rndalpha+0x53>
test   %r14d,%r14d
jle    117b <rndalpha+0x4b>
mov    %r14d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <lrand48@plt>
cltd
idiv   %r15d
add    $0x61,%dl
mov    %dl,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <rndalpha+0x30>
movslq %r14d,%rax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @rndalpha(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = add nsw i32 %7, 1
%9 = call i8* @malloc(i32 %8)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %35
12: ; preds = %2
store i32 0, i32* %5
br label %13
13: ; preds = %27, %12
%14 = load i32, i32* %5
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %30
17: ; preds = %13
%18 = call i32 (...) @lrand48()
%19 = load i32, i32* %4
%20 = srem i32 %18, %19
%21 = add nsw i32 97, %20
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %6
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 %22, i8* %26
br label %27
27: ; preds = %17
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %13
30: ; preds = %13
%31 = load i8*, i8** %6
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
br label %35
35: ; preds = %30, %2
%36 = load i8*, i8** %6
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %6
ret i8* %38
}

LLVM IR (-O2):
define noalias i8* @rndalpha(i32 %0, i32 %1) {
%3 = add nsw i32 %0, 1
%4 = tail call i8* @malloc(i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %22, label %6
6: ; preds = %2
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %19
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %17, %10 ]
%12 = tail call i32 (...) @lrand48()
%13 = srem i32 %12, %1
%14 = trunc i32 %13 to i8
%15 = add i8 %14, 97
%16 = getelementptr inbounds i8, i8* %4, i64 %11
store i8 %15, i8* %16
%17 = add nuw nsw i64 %11, 1
%18 = icmp eq i64 %17, %9
br i1 %18, label %19, label %10
19: ; preds = %10, %6
%20 = sext i32 %0 to i64
%21 = getelementptr inbounds i8, i8* %4, i64 %20
store i8 0, i8* %21
br label %22
22: ; preds = %19, %2
%23 = tail call i32 @free(i8* %4)
ret i8* %4
}