#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 *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *cin_com_set_string(char *val, char *def) {
  char *_val, *_rtn;
  if (val != NULL) {
    _val = val;
  } else {
    _val = def;
  }
  int slen;
  slen = strlen(_val);
  _rtn = malloc(sizeof(char) * slen);
  if (_rtn == NULL) {
    return NULL;
  }
  strcpy(_rtn, _val);
  return _rtn;
}


x86 assembly (clang, -O0):
<cin_com_set_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1158 <cin_com_set_string+0x28>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1160 <cin_com_set_string+0x30>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1197 <cin_com_set_string+0x67>
movq   $0x0,-0x8(%rbp)
jmp    11ac <cin_com_set_string+0x7c>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cin_com_set_string>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
test   %rdi,%rdi
cmovne %rdi,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     1160 <cin_com_set_string+0x30>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @cin_com_set_string(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i8*, i8** %4
store i8* %12, i8** %6
br label %15
13: ; preds = %2
%14 = load i8*, i8** %5
store i8* %14, i8** %6
br label %15
15: ; preds = %13, %11
%16 = load i8*, i8** %6
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = mul i64 1, %19
%21 = trunc i64 %20 to i32
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %15
store i8* null, i8** %3
br label %31
26: ; preds = %15
%27 = load i8*, i8** %7
%28 = load i8*, i8** %6
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = load i8*, i8** %7
store i8* %30, i8** %3
br label %31
31: ; preds = %26, %25
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
define i8* @cin_com_set_string(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = select i1 %3, i8* %1, i8* %0
%5 = tail call i32 @strlen(i8* %4)
%6 = tail call i8* @malloc(i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @strcpy(i8* %6, i8* %4)
br label %10
10: ; preds = %2, %8
ret i8* %6
}