#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 */
typedef int /*<<< orphan*/ UI;

/* Variables and functions */
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ UIT_PROMPT;
int /*<<< orphan*/ UIerror(int /*<<< orphan*/);
int general_allocate_string(int /*<<< orphan*/ *, char *, int,
                            int /*<<< orphan*/, int, char *, int, int,
                            int /*<<< orphan*/ *);
char *strdup(char const *);
int UI_dup_input_string(UI *ui, const char *prompt, int flags, char *result_buf,
                        int minsize, int maxsize) {
  char *prompt_copy = NULL;
  if (prompt) {
    prompt_copy = strdup(prompt);
    if (prompt_copy == NULL) {
      UIerror(ERR_R_MALLOC_FAILURE);
      return 0;
    }
  }
  return general_allocate_string(ui, prompt_copy, 1, UIT_PROMPT, flags,
                                 result_buf, minsize, maxsize, NULL);
}


x86 assembly (clang, -O0):
<UI_dup_input_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9d,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1199 <UI_dup_input_string+0x69>
mov    -0x18(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1194 <UI_dup_input_string+0x64>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
call   1030 <UIerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11da <UI_dup_input_string+0xaa>
jmp    1199 <UI_dup_input_string+0x69>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x2e38(%rip),%rax
mov    (%rax),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x28(%rbp),%r9
mov    -0x2c(%rbp),%r10d
mov    -0x30(%rbp),%eax
mov    $0x1,%edx
xor    %r11d,%r11d
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1040 <general_allocate_string@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UI_dup_input_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r9d,%r15d
mov    %r8d,%r14d
mov    %rcx,%r12
mov    %edx,%ebp
mov    %rdi,%rbx
test   %rsi,%rsi
je     116d <UI_dup_input_string+0x3d>
mov    %rsi,%rdi
call   1050 <strdup@plt>
mov    %rax,%rsi
test   %rax,%rax
jne    116f <UI_dup_input_string+0x3f>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
call   1030 <UIerror@plt>
xor    %eax,%eax
jmp    1199 <UI_dup_input_string+0x69>
xor    %esi,%esi
mov    0x2e6a(%rip),%rax
mov    (%rax),%ecx
sub    $0x8,%rsp
mov    %rbx,%rdi
mov    $0x1,%edx
mov    %ebp,%r8d
mov    %r12,%r9
push   $0x0
push   %r15
push   %r14
call   1040 <general_allocate_string@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ERR_R_MALLOC_FAILURE = global i32 0
@UIT_PROMPT = global i32 0
define i32 @UI_dup_input_string(i32* %0, i8* %1, i32 %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
store i32* %0, i32** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i8* null, i8** %14
%15 = load i8*, i8** %9
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %26
17: ; preds = %6
%18 = load i8*, i8** %9
%19 = call i8* @strdup(i8* %18)
store i8* %19, i8** %14
%20 = load i8*, i8** %14
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* @ERR_R_MALLOC_FAILURE
%24 = call i32 @UIerror(i32 %23)
store i32 0, i32* %7
br label %35
25: ; preds = %17
br label %26
26: ; preds = %25, %6
%27 = load i32*, i32** %8
%28 = load i8*, i8** %14
%29 = load i32, i32* @UIT_PROMPT
%30 = load i32, i32* %10
%31 = load i8*, i8** %11
%32 = load i32, i32* %12
%33 = load i32, i32* %13
%34 = call i32 @general_allocate_string(i32* %27, i8* %28, i32 1, i32 %29, i32 %30, i8* %31, i32 %32, i32 %33, i32* null)
store i32 %34, i32* %7
br label %35
35: ; preds = %26, %22
%36 = load i32, i32* %7
ret i32 %36
}

LLVM IR (-O2):
@ERR_R_MALLOC_FAILURE = global i32 0
@UIT_PROMPT = global i32 0
define i32 @UI_dup_input_string(i32* %0, i8* %1, i32 %2, i8* %3, i32 %4, i32 %5) {
%7 = icmp eq i8* %1, null
br i1 %7, label %14, label %8
8: ; preds = %6
%9 = tail call i8* @strdup(i8* %1)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @ERR_R_MALLOC_FAILURE
%13 = tail call i32 @UIerror(i32 %12)
br label %18
14: ; preds = %8, %6
%15 = phi i8* [ %9, %8 ], [ null, %6 ]
%16 = load i32, i32* @UIT_PROMPT
%17 = tail call i32 @general_allocate_string(i32* %0, i8* %15, i32 1, i32 %16, i32 %2, i8* %3, i32 %4, i32 %5, i32* null)
br label %18
18: ; preds = %14, %11
%19 = phi i32 [ 0, %11 ], [ %17, %14 ]
ret i32 %19
}