#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int rand();
char *generirajRandomStringNadAbecedom(char *abeceda,
                                       int duzinaRandomGeneriranogNiza,
                                       int duzinaAbecede) {
  char *niz;
  int i = 0, randomBroj = 0;
  niz = (char *)malloc(sizeof(char) * (duzinaRandomGeneriranogNiza + 1));
  if (niz == NULL) {
    printf("Unable to allocate memory.\n");
    exit(EXIT_FAILURE);
  }
  for (i = 0; i < duzinaRandomGeneriranogNiza; i++) {
    randomBroj = rand() % (duzinaAbecede - 1) + 1;
    *(niz + i) = *(abeceda + randomBroj);
  }
  *(niz + i) = '\0';
  return niz;
}


x86 assembly (clang, -O0):
<generirajRandomStringNadAbecedom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119c <generirajRandomStringNadAbecedom+0x5c>
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e9 <generirajRandomStringNadAbecedom+0xa9>
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a3 <generirajRandomStringNadAbecedom+0x63>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generirajRandomStringNadAbecedom>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %esi,%r15d
mov    %rdi,%r14
lea    0x1(%r15),%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11be <generirajRandomStringNadAbecedom+0x7e>
mov    %rax,%r13
test   %r15d,%r15d
jle    11a4 <generirajRandomStringNadAbecedom+0x64>
add    $0xffffffff,%r12d
mov    %r15d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1060 <rand@plt>
cltd
idiv   %r12d
movslq %edx,%rax
movzbl 0x1(%rax,%r14,1),%eax
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <generirajRandomStringNadAbecedom+0x40>
jmp    11a6 <generirajRandomStringNadAbecedom+0x66>
xor    %ebp,%ebp
movb   $0x0,0x0(%r13,%rbp,1)
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"Unable to allocate memory.\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @generirajRandomStringNadAbecedom(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
store i32 0, i32* %9
%10 = load i32, i32* %5
%11 = add nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = mul i64 1, %12
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %3
store i32 0, i32* %8
br label %24
24: ; preds = %43, %23
%25 = load i32, i32* %8
%26 = load i32, i32* %5
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %46
28: ; preds = %24
%29 = call i32 (...) @rand()
%30 = load i32, i32* %6
%31 = sub nsw i32 %30, 1
%32 = srem i32 %29, %31
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
%34 = load i8*, i8** %4
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = load i8*, i8** %7
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
br label %43
43: ; preds = %28
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %24
46: ; preds = %24
%47 = load i8*, i8** %7
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 0, i8* %50
%51 = load i8*, i8** %7
ret i8* %51
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [27 x i8] c"Unable to allocate memory.\00"
define i8* @generirajRandomStringNadAbecedom(i8* nocapture %0, i32 %1, i32 %2) {
%4 = add nsw i32 %1, 1
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %30
10: ; preds = %8
%11 = add nsw i32 %2, -1
%12 = zext i32 %1 to i64
br label %17
13: ; preds = %3
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %10, %17
%18 = phi i64 [ 0, %10 ], [ %26, %17 ]
%19 = tail call i32 (...) @rand()
%20 = srem i32 %19, %11
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = getelementptr inbounds i8, i8* %6, i64 %18
store i8 %24, i8* %25
%26 = add nuw nsw i64 %18, 1
%27 = icmp eq i64 %26, %12
br i1 %27, label %28, label %17
28: ; preds = %17
%29 = zext i32 %1 to i64
br label %30
30: ; preds = %8, %28
%31 = phi i64 [ %29, %28 ], [ 0, %8 ]
%32 = getelementptr inbounds i8, i8* %6, i64 %31
store i8 0, i8* %32
ret i8* %6
}