#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*/ clock();
scalar_t__ malloc(int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int strlen(char const *);
char *generateguid() {
  srand(clock());
  char *GUID = (char *)malloc(41);
  int t = 0;
  const char *szTemp = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
  const char *szHex = "0123456789ABCDEF-";
  int nLen = strlen(szTemp);
  for (t = 0; t < nLen + 1; t++) {
    int r = rand() % 16;
    char c = ' ';
    switch (szTemp[t]) {
    case 'x': {
      c = szHex[r];
    } break;
    case 'y': {
      c = szHex[(r & 0x03) | 0x08];
    } break;
    case '-': {
      c = '-';
    } break;
    case '4': {
      c = '4';
    } break;
    }
    GUID[t] = (t < nLen) ? c : 0x00;
  }
  GUID[40] = 0;
  return GUID;
}


x86 assembly (clang, -O0):
<generateguid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x29,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe7e(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe98(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    129f <generateguid+0x14f>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%edx
add    $0xf,%edx
test   %eax,%eax
mov    %eax,%ecx
cmovs  %edx,%ecx
and    $0xfffffff0,%ecx
sub    %ecx,%eax
mov    %eax,-0x28(%rbp)
movb   $0x20,-0x29(%rbp)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x30(%rbp)
sub    $0x2d,%eax
je     1252 <generateguid+0x102>
jmp    11f1 <generateguid+0xa1>
mov    -0x30(%rbp),%eax
sub    $0x34,%eax
je     125b <generateguid+0x10b>
jmp    1202 <generateguid+0xb2>
mov    -0x30(%rbp),%eax
sub    $0x78,%eax
je     1224 <generateguid+0xd4>
jmp    1213 <generateguid+0xc3>
mov    -0x30(%rbp),%eax
sub    $0x79,%eax
je     1237 <generateguid+0xe7>
jmp    125f <generateguid+0x10f>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
jmp    125f <generateguid+0x10f>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
and    $0x3,%ecx
or     $0x8,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
jmp    125f <generateguid+0x10f>
movb   $0x2d,-0x29(%rbp)
jmp    125f <generateguid+0x10f>
movb   $0x34,-0x29(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1277 <generateguid+0x127>
movsbl -0x29(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    1281 <generateguid+0x131>
xor    %eax,%eax
mov    %eax,-0x34(%rbp)
jmp    1281 <generateguid+0x131>
mov    -0x34(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a4 <generateguid+0x54>
mov    -0x8(%rbp),%rax
movb   $0x0,0x28(%rax)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateguid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r12d,%r12d
xor    %eax,%eax
call   1030 <clock@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x29,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0xe80(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
js     1234 <generateguid+0xe4>
mov    %eax,%ebx
mov    %eax,%r13d
add    $0x1,%ebx
xor    %ebp,%ebp
jmp    11c7 <generateguid+0x77>
nopl   0x0(%rax)
mov    $0x2d,%cl
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %r13,%rbp
movzbl %cl,%eax
cmovae %r12d,%eax
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
je     1234 <generateguid+0xe4>
xor    %eax,%eax
call   1070 <rand@plt>
lea    0xf(%rax),%esi
test   %eax,%eax
cmovns %eax,%esi
movsbl 0x0(%rbp,%r14,1),%edx
mov    $0x20,%cl
cmp    $0x77,%edx
jg     1200 <generateguid+0xb0>
cmp    $0x2d,%edx
je     11a0 <generateguid+0x50>
cmp    $0x34,%edx
jne    11b0 <generateguid+0x60>
mov    $0x34,%cl
jmp    11b0 <generateguid+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
and    $0xfffffff0,%esi
sub    %esi,%eax
cmp    $0x79,%edx
je     1220 <generateguid+0xd0>
cmp    $0x78,%edx
jne    11b0 <generateguid+0x60>
cltq
lea    0xe0d(%rip),%rcx
movzbl (%rax,%rcx,1),%ecx
jmp    11b0 <generateguid+0x60>
xchg   %ax,%ax
and    $0x3,%eax
lea    0xdfb(%rip),%rcx
movzbl 0x8(%rax,%rcx,1),%ecx
jmp    11b0 <generateguid+0x60>
movb   $0x0,0x28(%r15)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\00"
@.str.1 = [18 x i8] c"0123456789ABCDEF-\00"
define i8* @generateguid() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = call i32 (...) @clock()
%9 = call i32 @srand(i32 %8)
%10 = call i64 @malloc(i32 41)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %1
store i32 0, i32* %2
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8** %4
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %5
store i32 0, i32* %2
br label %14
14: ; preds = %59, %0
%15 = load i32, i32* %2
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %62
19: ; preds = %14
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 16
store i32 %21, i32* %6
store i8 32, i8* %7
%22 = load i8*, i8** %3
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
switch i32 %27, label %44 [
i32 120, label %28
i32 121, label %34
i32 45, label %42
i32 52, label %43
]
28: ; preds = %19
%29 = load i8*, i8** %4
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
store i8 %33, i8* %7
br label %44
34: ; preds = %19
%35 = load i8*, i8** %4
%36 = load i32, i32* %6
%37 = and i32 %36, 3
%38 = or i32 %37, 8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %35, i64 %39
%41 = load i8, i8* %40
store i8 %41, i8* %7
br label %44
42: ; preds = %19
store i8 45, i8* %7
br label %44
43: ; preds = %19
store i8 52, i8* %7
br label %44
44: ; preds = %19, %43, %42, %34, %28
%45 = load i32, i32* %2
%46 = load i32, i32* %5
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i8, i8* %7
%50 = sext i8 %49 to i32
br label %52
51: ; preds = %44
br label %52
52: ; preds = %51, %48
%53 = phi i32 [ %50, %48 ], [ 0, %51 ]
%54 = trunc i32 %53 to i8
%55 = load i8*, i8** %1
%56 = load i32, i32* %2
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 %54, i8* %58
br label %59
59: ; preds = %52
%60 = load i32, i32* %2
%61 = add nsw i32 %60, 1
store i32 %61, i32* %2
br label %14
62: ; preds = %14
%63 = load i8*, i8** %1
%64 = getelementptr inbounds i8, i8* %63, i64 40
store i8 0, i8* %64
%65 = load i8*, i8** %1
ret i8* %65
}

LLVM IR (-O2):
@.str = [37 x i8] c"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\00"
@.str.1 = [18 x i8] c"0123456789ABCDEF-\00"
define i8* @generateguid() {
%1 = tail call i32 (...) @clock()
%2 = tail call i32 @srand(i32 %1)
%3 = tail call i64 @malloc(i32 41)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%6 = icmp slt i32 %5, 0
br i1 %6, label %37, label %7
7: ; preds = %0
%8 = zext i32 %5 to i64
%9 = add nuw i32 %5, 1
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %7, %30
%12 = phi i64 [ 0, %7 ], [ %35, %30 ]
%13 = tail call i32 (...) @rand()
%14 = srem i32 %13, 16
%15 = getelementptr inbounds [37 x i8], [37 x i8]* @.str, i64 0, i64 %12
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
switch i32 %17, label %30 [
i32 120, label %18
i32 121, label %22
i32 45, label %28
i32 52, label %29
]
18: ; preds = %11
%19 = sext i32 %14 to i64
%20 = getelementptr inbounds [18 x i8], [18 x i8]* @.str.1, i64 0, i64 %19
%21 = load i8, i8* %20
br label %30
22: ; preds = %11
%23 = and i32 %14, 3
%24 = or i32 %23, 8
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds [18 x i8], [18 x i8]* @.str.1, i64 0, i64 %25
%27 = load i8, i8* %26
br label %30
28: ; preds = %11
br label %30
29: ; preds = %11
br label %30
30: ; preds = %11, %29, %28, %22, %18
%31 = phi i8 [ 32, %11 ], [ 52, %29 ], [ 45, %28 ], [ %27, %22 ], [ %21, %18 ]
%32 = icmp ult i64 %12, %8
%33 = select i1 %32, i8 %31, i8 0
%34 = getelementptr inbounds i8, i8* %4, i64 %12
store i8 %33, i8* %34
%35 = add nuw nsw i64 %12, 1
%36 = icmp eq i64 %35, %10
br i1 %36, label %37, label %11
37: ; preds = %30, %0
%38 = getelementptr inbounds i8, i8* %4, i64 40
store i8 0, i8* %38
ret i8* %4
}