#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 *);
char *malloc(int);
int rand();
char *random10(char *c) {
  char *p = malloc(sizeof(char));
  *p = rand() % 10;
  while (c != NULL && *p == *c) {
    free(p);
    p = malloc(sizeof(char));
    *p = rand() % 10;
  }
  return p;
}


x86 assembly (clang, -O0):
<random10>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %dl,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x11(%rbp)
je     1187 <random10+0x57>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1197 <random10+0x67>
jmp    11ca <random10+0x9a>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %dl,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    1161 <random10+0x31>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random10>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %al,(%rbx)
test   %r14,%r14
je     11b5 <random10+0x85>
nop
cmp    %al,(%r14)
jne    11b5 <random10+0x85>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %al,(%rbx)
cmp    %al,(%r14)
je     1175 <random10+0x45>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @random10(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = call i8* @malloc(i32 1)
store i8* %4, i8** %3
%5 = call i32 (...) @rand()
%6 = srem i32 %5, 10
%7 = trunc i32 %6 to i8
%8 = load i8*, i8** %3
store i8 %7, i8* %8
br label %9
9: ; preds = %22, %1
%10 = load i8*, i8** %2
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %15, %18
br label %20
20: ; preds = %12, %9
%21 = phi i1 [ false, %9 ], [ %19, %12 ]
br i1 %21, label %22, label %30
22: ; preds = %20
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
%25 = call i8* @malloc(i32 1)
store i8* %25, i8** %3
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 10
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %3
store i8 %28, i8* %29
br label %9
30: ; preds = %20
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
define noalias i8* @random10(i8* %0) {
%2 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 10
%5 = trunc i32 %4 to i8
store i8 %5, i8* %2
%6 = icmp eq i8* %0, null
br i1 %6, label %19, label %7
7: ; preds = %1
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, %5
br i1 %9, label %10, label %19
10: ; preds = %7, %10
%11 = phi i8* [ %13, %10 ], [ %2, %7 ]
%12 = tail call i32 @free(i8* %11)
%13 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%14 = tail call i32 (...) @rand()
%15 = srem i32 %14, 10
%16 = trunc i32 %15 to i8
store i8 %16, i8* %13
%17 = load i8, i8* %0
%18 = icmp eq i8 %17, %16
br i1 %18, label %10, label %19
19: ; preds = %10, %7, %1
%20 = phi i8* [ %2, %1 ], [ %2, %7 ], [ %13, %10 ]
ret i8* %20
}