#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*/ clear_tid();
int /*<<< orphan*/ free(char *);
scalar_t__ m_read(char *, int);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void *consumer(void *UNUSED) {
  char *dst = malloc(17);
  if (dst == NULL) {
    printf("dst malloc error\n");
    return NULL;
  }
  int read_length = 15;
  srand(time(NULL));
  while (read_length > 0) {
    int len = rand() % (17 / 2);
    len = read_length % (17 / 2);
    len++;
    if (0 == m_read(dst, len)) {
    } else {
    }
    read_length--;
  }
  free(dst);
  clear_tid();
}


x86 assembly (clang, -O0):
<consumer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x11,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11be <consumer+0x3e>
lea    0xe54(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    124a <consumer+0xca>
movl   $0xf,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    123a <consumer+0xba>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1030 <m_read@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1227 <consumer+0xa7>
jmp    122c <consumer+0xac>
jmp    122c <consumer+0xac>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d5 <consumer+0x55>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    $0x0,%al
call   1090 <clear_tid@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<consumer>:
push   %rbx
mov    $0x11,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     12e2 <consumer+0x162>
mov    %rax,%rbx
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1030 <m_read@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
call   1030 <m_read@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
call   1030 <m_read@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1030 <m_read@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <m_read@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1030 <m_read@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <m_read@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <m_read@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1030 <m_read@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
call   1030 <m_read@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
call   1030 <m_read@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1030 <m_read@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <m_read@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1030 <m_read@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <m_read@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
xor    %eax,%eax
call   1090 <clear_tid@plt>
jmp    12ee <consumer+0x16e>
lea    0xd17(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"dst malloc error\0A\00"
define i8* @consumer(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = call i8* @malloc(i32 17)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %38
12: ; preds = %1
store i32 15, i32* %5
%13 = call i32 @time(i32* null)
%14 = call i32 @srand(i32 %13)
br label %15
15: ; preds = %31, %12
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = call i32 (...) @rand()
%20 = srem i32 %19, 8
store i32 %20, i32* %6
%21 = load i32, i32* %5
%22 = srem i32 %21, 8
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
%25 = load i8*, i8** %4
%26 = load i32, i32* %6
%27 = call i64 @m_read(i8* %25, i32 %26)
%28 = icmp eq i64 0, %27
br i1 %28, label %29, label %30
29: ; preds = %18
br label %31
30: ; preds = %18
br label %31
31: ; preds = %30, %29
%32 = load i32, i32* %5
%33 = add nsw i32 %32, -1
store i32 %33, i32* %5
br label %15
34: ; preds = %15
%35 = load i8*, i8** %4
%36 = call i32 @free(i8* %35)
%37 = call i32 (...) @clear_tid()
br label %38
38: ; preds = %34, %10
%39 = load i8*, i8** %2
ret i8* %39
}

LLVM IR (-O2):
@str = [17 x i8] c"dst malloc error\00"
define noalias i8* @consumer(i8* nocapture readnone %0) {
%2 = tail call dereferenceable_or_null(17) i8* @malloc(i32 17)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %41
6: ; preds = %1
%7 = tail call i32 @time(i32* null)
%8 = tail call i32 @srand(i32 %7)
%9 = tail call i32 (...) @rand()
%10 = tail call i64 @m_read(i8* %2, i32 8)
%11 = tail call i32 (...) @rand()
%12 = tail call i64 @m_read(i8* %2, i32 7)
%13 = tail call i32 (...) @rand()
%14 = tail call i64 @m_read(i8* %2, i32 6)
%15 = tail call i32 (...) @rand()
%16 = tail call i64 @m_read(i8* %2, i32 5)
%17 = tail call i32 (...) @rand()
%18 = tail call i64 @m_read(i8* %2, i32 4)
%19 = tail call i32 (...) @rand()
%20 = tail call i64 @m_read(i8* %2, i32 3)
%21 = tail call i32 (...) @rand()
%22 = tail call i64 @m_read(i8* %2, i32 2)
%23 = tail call i32 (...) @rand()
%24 = tail call i64 @m_read(i8* %2, i32 1)
%25 = tail call i32 (...) @rand()
%26 = tail call i64 @m_read(i8* %2, i32 8)
%27 = tail call i32 (...) @rand()
%28 = tail call i64 @m_read(i8* %2, i32 7)
%29 = tail call i32 (...) @rand()
%30 = tail call i64 @m_read(i8* %2, i32 6)
%31 = tail call i32 (...) @rand()
%32 = tail call i64 @m_read(i8* %2, i32 5)
%33 = tail call i32 (...) @rand()
%34 = tail call i64 @m_read(i8* %2, i32 4)
%35 = tail call i32 (...) @rand()
%36 = tail call i64 @m_read(i8* %2, i32 3)
%37 = tail call i32 (...) @rand()
%38 = tail call i64 @m_read(i8* %2, i32 2)
%39 = tail call i32 @free(i8* %2)
%40 = tail call i32 (...) @clear_tid()
br label %41
41: ; preds = %6, %4
ret i8* null
}