#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *malloc(int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void *func() {
  void *rc_p;
  rc_p = malloc(sizeof(int));
  if (rc_p == NULL) {
    fprintf(stderr, "Cannot allocate memory");
    return NULL;
  }
  for (int ii = 0; ii < 10; ii++) {
    fprintf(stdout, ".");
    fflush(stdout);
    sleep(1);
  }
  fprintf(stdout, "\n");
  *(int *)rc_p = 3;
  return rc_p;
}


x86 assembly (clang, -O0):
<func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1183 <func+0x43>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f6 <func+0xb6>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11cf <func+0x8f>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118a <func+0x4a>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rax
movl   $0x3,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func>:
push   %r15
push   %r14
push   %rbx
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     128e <func+0x14e>
mov    0x2e76(%rip),%rbx
mov    (%rbx),%edi
lea    0xeac(%rip),%r15
mov    %r15,%rsi
call   1030 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1030 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1030 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1030 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1030 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1030 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1030 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1030 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1030 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1030 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%edi
lea    0xd99(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x3,(%r14)
jmp    12a3 <func+0x163>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
lea    0xd62(%rip),%rsi
call   1030 <fprintf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Cannot allocate memory\00"
@stdout = global i32 0
@.str.1 = [2 x i8] c".\00"
@.str.2 = [2 x i8] c"\0A\00"
define i8* @func() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = call i8* @malloc(i32 4)
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %1
br label %29
10: ; preds = %0
store i32 0, i32* %3
br label %11
11: ; preds = %20, %10
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 10
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = load i32, i32* @stdout
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @stdout
%18 = call i32 @fflush(i32 %17)
%19 = call i32 @sleep(i32 1)
br label %20
20: ; preds = %14
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %11
23: ; preds = %11
%24 = load i32, i32* @stdout
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = load i8*, i8** %2
%27 = bitcast i8* %26 to i32*
store i32 3, i32* %27
%28 = load i8*, i8** %2
store i8* %28, i8** %1
br label %29
29: ; preds = %23, %7
%30 = load i8*, i8** %1
ret i8* %30
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Cannot allocate memory\00"
@stdout = global i32 0
@.str.1 = [2 x i8] c".\00"
@.str.2 = [2 x i8] c"\0A\00"
define noalias i8* @func() {
%1 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%2 = icmp eq i8* %1, null
br i1 %2, label %57, label %3
3: ; preds = %0
%4 = load i32, i32* @stdout
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @stdout
%7 = tail call i32 @fflush(i32 %6)
%8 = tail call i32 @sleep(i32 1)
%9 = load i32, i32* @stdout
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @stdout
%12 = tail call i32 @fflush(i32 %11)
%13 = tail call i32 @sleep(i32 1)
%14 = load i32, i32* @stdout
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @stdout
%17 = tail call i32 @fflush(i32 %16)
%18 = tail call i32 @sleep(i32 1)
%19 = load i32, i32* @stdout
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @stdout
%22 = tail call i32 @fflush(i32 %21)
%23 = tail call i32 @sleep(i32 1)
%24 = load i32, i32* @stdout
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @stdout
%27 = tail call i32 @fflush(i32 %26)
%28 = tail call i32 @sleep(i32 1)
%29 = load i32, i32* @stdout
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* @stdout
%32 = tail call i32 @fflush(i32 %31)
%33 = tail call i32 @sleep(i32 1)
%34 = load i32, i32* @stdout
%35 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%36 = load i32, i32* @stdout
%37 = tail call i32 @fflush(i32 %36)
%38 = tail call i32 @sleep(i32 1)
%39 = load i32, i32* @stdout
%40 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%41 = load i32, i32* @stdout
%42 = tail call i32 @fflush(i32 %41)
%43 = tail call i32 @sleep(i32 1)
%44 = load i32, i32* @stdout
%45 = tail call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%46 = load i32, i32* @stdout
%47 = tail call i32 @fflush(i32 %46)
%48 = tail call i32 @sleep(i32 1)
%49 = load i32, i32* @stdout
%50 = tail call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%51 = load i32, i32* @stdout
%52 = tail call i32 @fflush(i32 %51)
%53 = tail call i32 @sleep(i32 1)
%54 = load i32, i32* @stdout
%55 = tail call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%56 = bitcast i8* %1 to i32*
store i32 3, i32* %56
br label %60
57: ; preds = %0
%58 = load i32, i32* @stderr
%59 = tail call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %60
60: ; preds = %3, %57
ret i8* %1
}