#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ passphrase_disable_echo1(int);
char *passphrase_read2(int, int);
int /*<<< orphan*/ passphrase_reenable_echo1(int);
int /*<<< orphan*/ passphrase_wipe1(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  char *passphrase;
  int fd = open("/dev/tty", O_RDONLY);
  if (fd == -1) {
    perror(*argv);
    return 1;
  }
  passphrase_disable_echo1(fd);
  printf("Passphrase: ");
  fflush(stdout);
  passphrase = passphrase_read2(fd, 1 | 2);
  if (passphrase == NULL) {
    perror(*argv);
    passphrase_reenable_echo1(fd);
    close(fd);
    return 1;
  }
  printf("You entered: %s\n", passphrase);
  passphrase_wipe1(passphrase);
  free(passphrase);
  passphrase_reenable_echo1(fd);
  close(fd);
  return 0;
  (void)argc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
lea    0xe3a(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11f0 <main+0x50>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1293 <main+0xf3>
mov    -0x1c(%rbp),%edi
call   10c0 <passphrase_disable_echo1@plt>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    -0x1c(%rbp),%edi
mov    $0x3,%esi
call   1070 <passphrase_read2@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1258 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1040 <passphrase_reenable_echo1@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1293 <main+0xf3>
mov    -0x18(%rbp),%rsi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <passphrase_wipe1@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
call   1040 <passphrase_reenable_echo1@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    0xe46(%rip),%rdi
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     123d <main+0x9d>
mov    %eax,%ebx
mov    %eax,%edi
call   10c0 <passphrase_disable_echo1@plt>
lea    0xe35(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    %ebx,%edi
mov    $0x3,%esi
call   1070 <passphrase_read2@plt>
test   %rax,%rax
je     124d <main+0xad>
mov    %rax,%rbp
lea    0xe0f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1060 <passphrase_wipe1@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %ebx,%edi
call   1040 <passphrase_reenable_echo1@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%rdi
call   10b0 <perror@plt>
mov    $0x1,%r15d
jmp    122f <main+0x8f>
mov    (%r14),%rdi
call   10b0 <perror@plt>
mov    %ebx,%edi
call   1040 <passphrase_reenable_echo1@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    $0x1,%r15d
jmp    122f <main+0x8f>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/tty\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"Passphrase: \00"
@stdout = global i32 0
@.str.2 = [17 x i8] c"You entered: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = load i8*, i8** %13
%15 = call i32 @perror(i8* %14)
store i32 1, i32* %3
br label %45
16: ; preds = %2
%17 = load i32, i32* %7
%18 = call i32 @passphrase_disable_echo1(i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @stdout
%21 = call i32 @fflush(i32 %20)
%22 = load i32, i32* %7
%23 = call i8* @passphrase_read2(i32 %22, i32 3)
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %34
26: ; preds = %16
%27 = load i8**, i8*** %5
%28 = load i8*, i8** %27
%29 = call i32 @perror(i8* %28)
%30 = load i32, i32* %7
%31 = call i32 @passphrase_reenable_echo1(i32 %30)
%32 = load i32, i32* %7
%33 = call i32 @close(i32 %32)
store i32 1, i32* %3
br label %45
34: ; preds = %16
%35 = load i8*, i8** %6
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = load i8*, i8** %6
%38 = call i32 @passphrase_wipe1(i8* %37)
%39 = load i8*, i8** %6
%40 = call i32 @free(i8* %39)
%41 = load i32, i32* %7
%42 = call i32 @passphrase_reenable_echo1(i32 %41)
%43 = load i32, i32* %7
%44 = call i32 @close(i32 %43)
store i32 0, i32* %3
br label %45
45: ; preds = %34, %26, %12
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/tty\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"Passphrase: \00"
@stdout = global i32 0
@.str.2 = [17 x i8] c"You entered: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @perror(i8* %7)
br label %27
9: ; preds = %2
%10 = tail call i32 @passphrase_disable_echo1(i32 %4)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @stdout
%13 = tail call i32 @fflush(i32 %12)
%14 = tail call i8* @passphrase_read2(i32 %4, i32 3)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %21
16: ; preds = %9
%17 = load i8*, i8** %1
%18 = tail call i32 @perror(i8* %17)
%19 = tail call i32 @passphrase_reenable_echo1(i32 %4)
%20 = tail call i32 @close(i32 %4)
br label %27
21: ; preds = %9
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%23 = tail call i32 @passphrase_wipe1(i8* %14)
%24 = tail call i32 @free(i8* %14)
%25 = tail call i32 @passphrase_reenable_echo1(i32 %4)
%26 = tail call i32 @close(i32 %4)
br label %27
27: ; preds = %21, %16, %6
%28 = phi i32 [ 1, %6 ], [ 1, %16 ], [ 0, %21 ]
ret i32 %28
}