#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 */
void *calloc(long, long);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long, long, long);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
void *sc_do_alloc(long a, long b) {
  void *r;
  if (a < 1)
    a = 1;
  if (b < 1)
    b = 1;
  r = calloc(a, b);
  while (r == NULL) {
    fprintf(stderr,
            "Failed to allocated %ld chunks of %ld bytes (%ld bytes total)\n",
            a, b, a * b);
    sleep(1);
    r = calloc(a, b);
  }
  return r;
}


x86 assembly (clang, -O0):
<sc_do_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x1,-0x8(%rbp)
jge    1153 <sc_do_alloc+0x23>
movq   $0x1,-0x8(%rbp)
cmpq   $0x1,-0x10(%rbp)
jge    1166 <sc_do_alloc+0x36>
movq   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c8 <sc_do_alloc+0x98>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%r8
imul   -0x10(%rbp),%r8
lea    0xe5d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
jmp    1177 <sc_do_alloc+0x47>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sc_do_alloc>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
test   %rdi,%rdi
mov    $0x1,%ebx
cmovle %rbx,%r14
test   %rsi,%rsi
cmovg  %rsi,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <calloc@plt>
test   %rax,%rax
jne    11af <sc_do_alloc+0x7f>
mov    %rbx,%r15
imul   %r14,%r15
mov    0x2e73(%rip),%r13
lea    0xe8c(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x0(%r13),%edi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %r15,%r8
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <calloc@plt>
test   %rax,%rax
je     1180 <sc_do_alloc+0x50>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [63 x i8] c"Failed to allocated %ld chunks of %ld bytes (%ld bytes total)\0A\00"
define i8* @sc_do_alloc(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i64 %0, i64* %3
store i64 %1, i64* %4
%6 = load i64, i64* %3
%7 = icmp slt i64 %6, 1
br i1 %7, label %8, label %9
8: ; preds = %2
store i64 1, i64* %3
br label %9
9: ; preds = %8, %2
%10 = load i64, i64* %4
%11 = icmp slt i64 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %9
store i64 1, i64* %4
br label %13
13: ; preds = %12, %9
%14 = load i64, i64* %3
%15 = load i64, i64* %4
%16 = call i8* @calloc(i64 %14, i64 %15)
store i8* %16, i8** %5
br label %17
17: ; preds = %20, %13
%18 = load i8*, i8** %5
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %32
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = load i64, i64* %3
%23 = load i64, i64* %4
%24 = load i64, i64* %3
%25 = load i64, i64* %4
%26 = mul nsw i64 %24, %25
%27 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i64 %22, i64 %23, i64 %26)
%28 = call i32 @sleep(i32 1)
%29 = load i64, i64* %3
%30 = load i64, i64* %4
%31 = call i8* @calloc(i64 %29, i64 %30)
store i8* %31, i8** %5
br label %17
32: ; preds = %17
%33 = load i8*, i8** %5
ret i8* %33
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [63 x i8] c"Failed to allocated %ld chunks of %ld bytes (%ld bytes total)\0A\00"
define i8* @sc_do_alloc(i64 %0, i64 %1) {
%3 = icmp sgt i64 %0, 1
%4 = select i1 %3, i64 %0, i64 1
%5 = icmp sgt i64 %1, 1
%6 = select i1 %5, i64 %1, i64 1
%7 = tail call i8* @calloc(i64 %4, i64 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %17
9: ; preds = %2
%10 = mul nsw i64 %6, %4
br label %11
11: ; preds = %9, %11
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i64 %4, i64 %6, i64 %10)
%14 = tail call i32 @sleep(i32 1)
%15 = tail call i8* @calloc(i64 %4, i64 %6)
%16 = icmp eq i8* %15, null
br i1 %16, label %11, label %17
17: ; preds = %11, %2
%18 = phi i8* [ %7, %2 ], [ %15, %11 ]
ret i8* %18
}