#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*/ UI_F_UI_DUP_INPUT_STRING;
int /*<<< orphan*/ UIerr(int /*<<< orphan*/, 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) {
      UIerr(UI_F_UI_DUP_INPUT_STRING, 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     11a2 <UI_dup_input_string+0x72>
mov    -0x18(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    119d <UI_dup_input_string+0x6d>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
call   1030 <UIerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e3 <UI_dup_input_string+0xb3>
jmp    11a2 <UI_dup_input_string+0x72>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x2e2f(%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     1176 <UI_dup_input_string+0x46>
mov    %rsi,%rdi
call   1050 <strdup@plt>
mov    %rax,%rsi
test   %rax,%rax
jne    1178 <UI_dup_input_string+0x48>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
call   1030 <UIerr@plt>
xor    %eax,%eax
jmp    11a2 <UI_dup_input_string+0x72>
xor    %esi,%esi
mov    0x2e61(%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):
@UI_F_UI_DUP_INPUT_STRING = global i32 0
@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 %27
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 %26
22: ; preds = %17
%23 = load i32, i32* @UI_F_UI_DUP_INPUT_STRING
%24 = load i32, i32* @ERR_R_MALLOC_FAILURE
%25 = call i32 @UIerr(i32 %23, i32 %24)
store i32 0, i32* %7
br label %36
26: ; preds = %17
br label %27
27: ; preds = %26, %6
%28 = load i32*, i32** %8
%29 = load i8*, i8** %14
%30 = load i32, i32* @UIT_PROMPT
%31 = load i32, i32* %10
%32 = load i8*, i8** %11
%33 = load i32, i32* %12
%34 = load i32, i32* %13
%35 = call i32 @general_allocate_string(i32* %28, i8* %29, i32 1, i32 %30, i32 %31, i8* %32, i32 %33, i32 %34, i32* null)
store i32 %35, i32* %7
br label %36
36: ; preds = %27, %22
%37 = load i32, i32* %7
ret i32 %37
}

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