#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*/ _SC_PASS_MAX;
long __sysconf(int /*<<< orphan*/);
char *getpass_r(char const *, char *, size_t);
char *malloc(size_t);
char *getpass(const char *prompt) {
  static char e[] = "";
  static char *buf;
  static long bufsiz;
  char *rv;
  if (buf == NULL) {
    if ((bufsiz = __sysconf(_SC_PASS_MAX)) == -1)
      return e;
    if ((buf = malloc((size_t)bufsiz)) == NULL)
      return e;
  }
  if ((rv = getpass_r(prompt, buf, (size_t)bufsiz)) == NULL)
    return e;
  return rv;
}


x86 assembly (clang, -O0):
<getpass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,0x2f04(%rip)
jne    11ab <getpass+0x7b>
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
call   1030 <__sysconf@plt>
mov    %rax,0x2ef1(%rip)
cmp    $0xffffffffffffffff,%rax
jne    1179 <getpass+0x49>
lea    0x2ed0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e8 <getpass+0xb8>
mov    0x2ed0(%rip),%rdi
call   1040 <malloc@plt>
mov    %rax,0x2ebc(%rip)
cmp    $0x0,%rax
jne    11a6 <getpass+0x76>
lea    0x2ea3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e8 <getpass+0xb8>
jmp    11ab <getpass+0x7b>
mov    -0x10(%rbp),%rdi
mov    0x2e92(%rip),%rsi
mov    0x2e93(%rip),%rdx
call   1050 <getpass_r@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e0 <getpass+0xb0>
lea    0x2e69(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e8 <getpass+0xb8>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpass>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2f09(%rip),%rsi
test   %rsi,%rsi
je     116d <getpass+0x3d>
mov    0x2f05(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rdx
call   1050 <getpass_r@plt>
test   %rax,%rax
lea    0x2ee0(%rip),%rbx
cmovne %rax,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
call   1030 <__sysconf@plt>
mov    %rax,0x2ece(%rip)
lea    0x2eb7(%rip),%rbx
cmp    $0xffffffffffffffff,%rax
je     1164 <getpass+0x34>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <malloc@plt>
mov    %rax,%rsi
mov    %rax,0x2ea4(%rip)
test   %rax,%rax
jne    114b <getpass+0x1b>
jmp    1164 <getpass+0x34>

LLVM IR (-O0):
@getpass.e = internal global [1 x i8] zeroinitializer
@getpass.buf = internal global i8* null
@getpass.bufsiz = internal global i64 0
@_SC_PASS_MAX = global i32 0
define i8* @getpass(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** @getpass.buf
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %18
7: ; preds = %1
%8 = load i32, i32* @_SC_PASS_MAX
%9 = call i64 @__sysconf(i32 %8)
store i64 %9, i64* @getpass.bufsiz
%10 = icmp eq i64 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %7
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @getpass.e, i64 0, i64 0), i8** %2
br label %27
12: ; preds = %7
%13 = load i64, i64* @getpass.bufsiz
%14 = call i8* @malloc(i64 %13)
store i8* %14, i8** @getpass.buf
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %12
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @getpass.e, i64 0, i64 0), i8** %2
br label %27
17: ; preds = %12
br label %18
18: ; preds = %17, %1
%19 = load i8*, i8** %3
%20 = load i8*, i8** @getpass.buf
%21 = load i64, i64* @getpass.bufsiz
%22 = call i8* @getpass_r(i8* %19, i8* %20, i64 %21)
store i8* %22, i8** %4
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %18
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @getpass.e, i64 0, i64 0), i8** %2
br label %27
25: ; preds = %18
%26 = load i8*, i8** %4
store i8* %26, i8** %2
br label %27
27: ; preds = %25, %24, %16, %11
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
@getpass.e = internal global [1 x i8] zeroinitializer
@getpass.buf = internal unnamed_addr global i8* null
@getpass.bufsiz = internal unnamed_addr global i64 0
@_SC_PASS_MAX = global i32 0
define i8* @getpass(i8* %0) {
%2 = load i8*, i8** @getpass.buf
%3 = icmp eq i8* %2, null
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = load i64, i64* @getpass.bufsiz
br label %13
6: ; preds = %1
%7 = load i32, i32* @_SC_PASS_MAX
%8 = tail call i64 @__sysconf(i32 %7)
store i64 %8, i64* @getpass.bufsiz
%9 = icmp eq i64 %8, -1
br i1 %9, label %19, label %10
10: ; preds = %6
%11 = tail call i8* @malloc(i64 %8)
store i8* %11, i8** @getpass.buf
%12 = icmp eq i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %4, %10
%14 = phi i64 [ %8, %10 ], [ %5, %4 ]
%15 = phi i8* [ %11, %10 ], [ %2, %4 ]
%16 = tail call i8* @getpass_r(i8* %0, i8* %15, i64 %14)
%17 = icmp eq i8* %16, null
%18 = select i1 %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @getpass.e, i64 0, i64 0), i8* %16
br label %19
19: ; preds = %13, %10, %6
%20 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @getpass.e, i64 0, i64 0), %6 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @getpass.e, i64 0, i64 0), %10 ], [ %18, %13 ]
ret i8* %20
}