#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int mcparm_string(char *s, void *vptr) {
  char **v = (char **)vptr;
  if (!s) {
    *v = NULL;
    return (1);
  }
  *v = (char *)malloc(strlen(s) + 1);
  if (*v == NULL) {
    exit(-fprintf(stderr, "Error: Out of memory %li (mcparm_string).\n",
                  (long)strlen(s) + 1));
  }
  strcpy(*v, s);
  return 1;
}


x86 assembly (clang, -O0):
<mcparm_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118a <mcparm_string+0x3a>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1202 <mcparm_string+0xb2>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11eb <mcparm_string+0x9b>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xe23(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
sub    %eax,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mcparm_string>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     1182 <mcparm_string+0x32>
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1193 <mcparm_string+0x43>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
jmp    1189 <mcparm_string+0x39>
movq   $0x0,(%r14)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e46(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
lea    0xe51(%rip),%rsi
mov    %ebp,%edi
call   1050 <fprintf@plt>
neg    %eax
mov    %eax,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"Error: Out of memory %li (mcparm_string).\0A\00"
define i32 @mcparm_string(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8**
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = bitcast i8* %7 to i8**
store i8** %8, i8*** %6
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = load i8**, i8*** %6
store i8* null, i8** %12
store i32 1, i32* %3
br label %36
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 1
%17 = call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
%19 = load i8**, i8*** %6
store i8* %18, i8** %19
%20 = load i8**, i8*** %6
%21 = load i8*, i8** %20
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %31
23: ; preds = %13
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %4
%26 = call i64 @strlen(i8* %25)
%27 = add nsw i64 %26, 1
%28 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i64 %27)
%29 = sub nsw i32 0, %28
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %13
%32 = load i8**, i8*** %6
%33 = load i8*, i8** %32
%34 = load i8*, i8** %4
%35 = call i32 @strcpy(i8* %33, i8* %34)
store i32 1, i32* %3
br label %36
36: ; preds = %31, %11
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"Error: Out of memory %li (mcparm_string).\0A\00"
define i32 @mcparm_string(i8* %0, i8* nocapture writeonly %1) {
%3 = bitcast i8* %1 to i8**
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %6
5: ; preds = %2
store i8* null, i8** %3
br label %21
6: ; preds = %2
%7 = tail call i64 @strlen(i8* %0)
%8 = add nsw i64 %7, 1
%9 = tail call i64 @malloc(i64 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %3
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %19
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = tail call i64 @strlen(i8* %0)
%15 = add nsw i64 %14, 1
%16 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i64 %15)
%17 = sub nsw i32 0, %16
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %6
%20 = tail call i32 @strcpy(i8* %10, i8* %0)
br label %21
21: ; preds = %19, %5
ret i32 1
}