#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 */
char *ShareMallocM1c(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ realloc(char *, int);
char *ShareReallocM1c(char *s, int size) {
  if (!s) {
    s = ShareMallocM1c(size);
    return s;
  }
  if ((s = (char *)realloc(s, size * sizeof(char))) == NULL) {
    printf("char * realloc error!");
    exit(1);
  }
  return s;
}


x86 assembly (clang, -O0):
<ShareReallocM1c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1173 <ShareReallocM1c+0x33>
mov    -0x14(%rbp),%edi
call   1040 <ShareMallocM1c@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b2 <ShareReallocM1c+0x72>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11aa <ShareReallocM1c+0x6a>
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ShareReallocM1c>:
push   %rax
test   %rdi,%rdi
je     1152 <ShareReallocM1c+0x12>
call   1050 <realloc@plt>
test   %rax,%rax
je     115a <ShareReallocM1c+0x1a>
pop    %rcx
ret
mov    %esi,%edi
pop    %rax
jmp    1040 <ShareMallocM1c@plt>
lea    0xe9f(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"char * realloc error!\00"
define i8* @ShareReallocM1c(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* %5
%10 = call i8* @ShareMallocM1c(i32 %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
store i8* %11, i8** %3
br label %26
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call i64 @realloc(i8* %13, i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %4
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %12
%25 = load i8*, i8** %4
store i8* %25, i8** %3
br label %26
26: ; preds = %24, %8
%27 = load i8*, i8** %3
ret i8* %27
}

LLVM IR (-O2):
@.str = [22 x i8] c"char * realloc error!\00"
define i8* @ShareReallocM1c(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i8* @ShareMallocM1c(i32 %1)
br label %14
6: ; preds = %2
%7 = tail call i64 @realloc(i8* %0, i32 %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %6
%13 = inttoptr i64 %7 to i8*
br label %14
14: ; preds = %12, %4
%15 = phi i8* [ %13, %12 ], [ %5, %4 ]
ret i8* %15
}