#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*/ ErrMsg(char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ restart(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *malloc_char(char *str, char *str_name) {
  char *p;
  p = (char *)malloc(sizeof(char) * (strlen(str) + 1));
  if (!p) {
    ErrMsg("* malloc error in '%s'\n", str_name);
    restart(1);
  }
  strcpy(p, str);
  return p;
}


x86 assembly (clang, -O0):
<malloc_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a2 <malloc_char+0x52>
mov    -0x10(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1060 <ErrMsg@plt>
mov    $0x1,%edi
call   1030 <restart@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<malloc_char>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1189 <malloc_char+0x39>
lea    0xe89(%rip),%rdi
mov    %r15,%rsi
call   1060 <ErrMsg@plt>
mov    $0x1,%edi
call   1030 <restart@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"* malloc error in '%s'\0A\00"
define i8* @malloc_char(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = add nsw i32 %7, 1
%9 = sext i32 %8 to i64
%10 = mul i64 1, %9
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %20, label %16
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = call i32 @ErrMsg(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @restart(i32 1)
br label %20
20: ; preds = %16, %2
%21 = load i8*, i8** %5
%22 = load i8*, i8** %3
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i8*, i8** %5
ret i8* %24
}

LLVM IR (-O2):
@.str = [24 x i8] c"* malloc error in '%s'\0A\00"
define i8* @malloc_char(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @ErrMsg(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %1)
%10 = tail call i32 @restart(i32 1)
br label %11
11: ; preds = %8, %2
%12 = tail call i32 @strcpy(i8* %6, i8* %0)
ret i8* %6
}