#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ warn(char *);
char *xgetpass(int /*<<< orphan*/ *);
char *askpass_tty(char *prompt) {
  FILE *tty;
  char *pw;
  if ((tty = fopen("/dev/tty", "r+")) == NULL) {
    warn("open /dev/tty failed");
    return NULL;
  }
  fputs(prompt, tty);
  fflush(tty);
  pw = xgetpass(tty);
  fputc('\n', tty);
  fclose(tty);
  if (!pw)
    warn("get password failed");
  return pw;
}


x86 assembly (clang, -O0):
<askpass_tty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe7d(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b6 <askpass_tty+0x46>
lea    0xe68(%rip),%rdi
call   1030 <warn@plt>
movq   $0x0,-0x8(%rbp)
jmp    120f <askpass_tty+0x9f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1080 <fflush@plt>
mov    -0x18(%rbp),%rdi
call   1040 <xgetpass@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1070 <fputc@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1207 <askpass_tty+0x97>
lea    0xe1f(%rip),%rdi
call   1030 <warn@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<askpass_tty>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe82(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11d3 <askpass_tty+0x63>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <fputs@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    %rbx,%rdi
call   1040 <xgetpass@plt>
mov    %rax,%r14
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %r14,%r14
jne    11e2 <askpass_tty+0x72>
lea    0xe50(%rip),%rdi
jmp    11da <askpass_tty+0x6a>
lea    0xe32(%rip),%rdi
call   1030 <warn@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/tty\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [21 x i8] c"open /dev/tty failed\00"
@.str.3 = [20 x i8] c"get password failed\00"
define i8* @askpass_tty(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @warn(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %2
br label %28
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i32*, i32** %4
%13 = call i32 @fputs(i8* %11, i32* %12)
%14 = load i32*, i32** %4
%15 = call i32 @fflush(i32* %14)
%16 = load i32*, i32** %4
%17 = call i8* @xgetpass(i32* %16)
store i8* %17, i8** %5
%18 = load i32*, i32** %4
%19 = call i32 @fputc(i8 signext 10, i32* %18)
%20 = load i32*, i32** %4
%21 = call i32 @fclose(i32* %20)
%22 = load i8*, i8** %5
%23 = icmp ne i8* %22, null
br i1 %23, label %26, label %24
24: ; preds = %10
%25 = call i32 @warn(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %24, %10
%27 = load i8*, i8** %5
store i8* %27, i8** %2
br label %28
28: ; preds = %26, %8
%29 = load i8*, i8** %2
ret i8* %29
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/tty\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [21 x i8] c"open /dev/tty failed\00"
@.str.3 = [20 x i8] c"get password failed\00"
define i8* @askpass_tty(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = tail call i32 @fputs(i8* %0, i32* %2)
%6 = tail call i32 @fflush(i32* %2)
%7 = tail call i8* @xgetpass(i32* %2)
%8 = tail call i32 @fputc(i8 signext 10, i32* %2)
%9 = tail call i32 @fclose(i32* %2)
%10 = icmp eq i8* %7, null
br i1 %10, label %11, label %14
11: ; preds = %4, %1
%12 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), %1 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), %4 ]
%13 = tail call i32 @warn(i8* %12)
br label %14
14: ; preds = %11, %4
%15 = phi i8* [ %7, %4 ], [ null, %11 ]
ret i8* %15
}