#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int getpid();
int /*<<< orphan*/ putchar(char);
int random();
int /*<<< orphan*/ srandom(int);
int time(int /*<<< orphan*/ *);
int random_main(int hex, int argc, char **argv) {
  int num;
  srandom(getpid() * time(NULL));
  if (argc != 2)
    exit(1);
  num = atoi(argv[1]);
  while (num-- > 0) {
    if (hex)
      putchar("0123456789abcdef"[random() % 16]);
    else
      putchar("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
                  [random() % 62]);
  }
  putchar('\n');
  return 0;
}


x86 assembly (clang, -O0):
<random_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    -0x18(%rbp),%edi
imul   %eax,%edi
call   1040 <srandom@plt>
cmpl   $0x2,-0x8(%rbp)
je     11b4 <random_main+0x44>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jle    1230 <random_main+0xc0>
cmpl   $0x0,-0x4(%rbp)
je     1209 <random_main+0x99>
mov    $0x0,%al
call   1070 <random@plt>
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0xe05(%rip),%rax
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
jmp    122b <random_main+0xbb>
mov    $0x0,%al
call   1070 <random@plt>
mov    $0x3e,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0xdef(%rip),%rax
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
jmp    11c4 <random_main+0x54>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebx
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1060 <time@plt>
imul   %eax,%ebp
mov    %ebp,%edi
call   1040 <srandom@plt>
cmp    $0x2,%r15d
jne    1243 <random_main+0xd3>
mov    0x8(%r14),%rdi
call   1080 <atoi@plt>
test   %eax,%eax
jle    122c <random_main+0xbc>
mov    %eax,%ebp
add    $0x1,%ebp
lea    0xe51(%rip),%r14
lea    0xe39(%rip),%r15
jmp    120d <random_main+0x9d>
nopl   0x0(%rax)
movslq %eax,%rcx
imul   $0xffffffff84210843,%rcx,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x5,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x6,%edx
mov    %ecx,%esi
sub    %edx,%esi
add    %ecx,%esi
add    %eax,%esi
movslq %esi,%rax
add    %r14,%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jbe    122c <random_main+0xbc>
xor    %eax,%eax
call   1070 <random@plt>
test   %ebx,%ebx
je     11d0 <random_main+0x60>
lea    0xf(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffff0,%ecx
sub    %ecx,%eax
cltq
add    %r15,%rax
jmp    11fd <random_main+0x8d>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"0123456789abcdef\00"
@.str.1 = [63 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define i32 @random_main(i32 %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
%8 = call i32 (...) @getpid()
%9 = call i32 @time(i32* null)
%10 = mul nsw i32 %8, %9
%11 = call i32 @srandom(i32 %10)
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %3
%17 = load i8**, i8*** %6
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %7
br label %21
21: ; preds = %42, %16
%22 = load i32, i32* %7
%23 = add nsw i32 %22, -1
store i32 %23, i32* %7
%24 = icmp sgt i32 %22, 0
br i1 %24, label %25, label %43
25: ; preds = %21
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = call i32 (...) @random()
%30 = srem i32 %29, 16
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = call i32 @putchar(i8 signext %33)
br label %42
35: ; preds = %25
%36 = call i32 (...) @random()
%37 = srem i32 %36, 62
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [63 x i8], [63 x i8]* @.str.1, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = call i32 @putchar(i8 signext %40)
br label %42
42: ; preds = %35, %28
br label %21
43: ; preds = %21
%44 = call i32 @putchar(i8 signext 10)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789abcdef\00"
@.str.1 = [63 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define i32 @random_main(i32 %0, i32 %1, i8** nocapture %2) {
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 @time(i32* null)
%6 = mul nsw i32 %5, %4
%7 = tail call i32 @srandom(i32 %6)
%8 = icmp eq i32 %1, 2
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %3
%12 = getelementptr inbounds i8*, i8** %2, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %35
16: ; preds = %11
%17 = icmp eq i32 %0, 0
br label %18
18: ; preds = %16, %30
%19 = phi i32 [ %14, %16 ], [ %20, %30 ]
%20 = add nsw i32 %19, -1
%21 = tail call i32 (...) @random()
br i1 %17, label %26, label %22
22: ; preds = %18
%23 = srem i32 %21, 16
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %24
br label %30
26: ; preds = %18
%27 = srem i32 %21, 62
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [63 x i8], [63 x i8]* @.str.1, i64 0, i64 %28
br label %30
30: ; preds = %26, %22
%31 = phi i8* [ %29, %26 ], [ %25, %22 ]
%32 = load i8, i8* %31
%33 = tail call i32 @putchar(i8 signext %32)
%34 = icmp ugt i32 %19, 1
br i1 %34, label %18, label %35
35: ; preds = %30, %11
%36 = tail call i32 @putchar(i8 signext 10)
ret i32 0
}