#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
char *fgetpass(char *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strncmp(char *, char *, size_t);
void getpass(char *buf, size_t len, int confirm) {
  int diff = 0;
  do {
    if (diff) {
      printf("inputs did not match\n");
    }
    printf(" input passphrase: ");
    char *r = fgetpass(buf, len, stdin);
    if (!r) {
      do {
        fflush(stdout);
        fprintf(stderr, "fgetpass returned NULL reading buf of %zu?", len);
        fprintf(stderr, "\n");
      } while (0);
      exit(EXIT_FAILURE);
    }
    printf("\n");
    if (confirm) {
      printf("repeat passphrase: ");
      char buf2[len];
      r = fgetpass(buf2, len, stdin);
      if (!r) {
        do {
          fflush(stdout);
          fprintf(stderr, "fgetpass returned NULL reading buf of %zu?", len);
          fprintf(stderr, "\n");
        } while (0);
        exit(EXIT_FAILURE);
      }
      printf("\n");
      diff = strncmp(buf, buf2, len);
    }
  } while (diff);
}


x86 assembly (clang, -O0):
<getpass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1190 <getpass+0x30>
lea    0xe75(%rip),%rdi
call   1040 <printf@plt>
lea    0xe7f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
call   1050 <fgetpass@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1214 <getpass+0xb4>
jmp    11c6 <getpass+0x66>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xdf9(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
je     12fd <getpass+0x19d>
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rsi
mov    0x2d80(%rip),%rax
mov    (%rax),%edx
call   1050 <fgetpass@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12d6 <getpass+0x176>
jmp    1283 <getpass+0x123>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
lea    0xd58(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12c8 <getpass+0x168>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xd37(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
call   1030 <strncmp@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
jmp    1302 <getpass+0x1a2>
cmpl   $0x0,-0x18(%rbp)
jne    117a <getpass+0x1a>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpass>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,-0x2c(%rbp)
mov    %rsi,%r12
mov    %rdi,%r15
xor    %r13d,%r13d
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
mov    %rax,-0x38(%rbp)
jmp    11d7 <getpass+0x57>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <strncmp@plt>
mov    %eax,%r13d
mov    %r14,%rsp
test   %r13d,%r13d
je     1299 <getpass+0x119>
test   %r13d,%r13d
je     11e8 <getpass+0x68>
lea    0xe72(%rip),%rdi
call   1050 <puts@plt>
lea    0xe11(%rip),%rdi
call   1060 <printf@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <fgetpass@plt>
test   %rax,%rax
je     1253 <getpass+0xd3>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x0,-0x2c(%rbp)
je     11ce <getpass+0x4e>
lea    0xe1d(%rip),%rdi
call   1060 <printf@plt>
mov    %rsp,%r14
mov    %rsp,%rbx
sub    -0x38(%rbp),%rbx
mov    %rbx,%rsp
mov    0x2dab(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <fgetpass@plt>
test   %rax,%rax
jne    11b0 <getpass+0x30>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    0x2d70(%rip),%rbx
mov    (%rbx),%edi
lea    0xda3(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdbb(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"inputs did not match\0A\00"
@.str.1 = [20 x i8] c" input passphrase: \00"
@stdin = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str.2 = [43 x i8] c"fgetpass returned NULL reading buf of %zu?\00"
@.str.3 = [2 x i8] c"\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [20 x i8] c"repeat passphrase: \00"
define void @getpass(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %11
11: ; preds = %70, %3
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%18 = load i8*, i8** %4
%19 = load i64, i64* %5
%20 = load i32, i32* @stdin
%21 = call i8* @fgetpass(i8* %18, i64 %19, i32 %20)
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = icmp ne i8* %22, null
br i1 %23, label %36, label %24
24: ; preds = %16
br label %25
25: ; preds = %24
%26 = load i32, i32* @stdout
%27 = call i32 @fflush(i32 %26)
%28 = load i32, i32* @stderr
%29 = load i64, i64* %5
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i64 %29)
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %25
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %16
%37 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* %6
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %69
40: ; preds = %36
%41 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%42 = load i64, i64* %5
%43 = call i8* @llvm.stacksave()
store i8* %43, i8** %9
%44 = alloca i8, i64 %42
store i64 %42, i64* %10
%45 = load i64, i64* %5
%46 = load i32, i32* @stdin
%47 = call i8* @fgetpass(i8* %44, i64 %45, i32 %46)
store i8* %47, i8** %8
%48 = load i8*, i8** %8
%49 = icmp ne i8* %48, null
br i1 %49, label %63, label %50
50: ; preds = %40
br label %51
51: ; preds = %50
%52 = load i32, i32* @stdout
%53 = call i32 @fflush(i32 %52)
%54 = load i32, i32* @stderr
%55 = load i64, i64* %5
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i64 %55)
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %59
59: ; preds = %51
br label %60
60: ; preds = %59
%61 = load i32, i32* @EXIT_FAILURE
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %40
%64 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%65 = load i8*, i8** %4
%66 = load i64, i64* %5
%67 = call i32 @strncmp(i8* %65, i8* %44, i64 %66)
store i32 %67, i32* %7
%68 = load i8*, i8** %9
br label %69
69: ; preds = %63, %36
br label %70
70: ; preds = %69
%71 = load i32, i32* %7
%72 = icmp ne i32 %71, 0
br i1 %72, label %11, label %73
73: ; preds = %70
ret void
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c" input passphrase: \00"
@stdin = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@.str.2 = [43 x i8] c"fgetpass returned NULL reading buf of %zu?\00"
@.str.3 = [2 x i8] c"\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [20 x i8] c"repeat passphrase: \00"
@str = [21 x i8] c"inputs did not match\00"
define void @getpass(i8* %0, i64 %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br label %5
5: ; preds = %45, %3
%6 = phi i32 [ 0, %3 ], [ %46, %45 ]
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @stdin
%13 = call i8* @fgetpass(i8* %0, i64 %1, i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %24
15: ; preds = %10
%16 = load i32, i32* @stdout
%17 = call i32 @fflush(i32 %16)
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i64 %1)
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %10
%25 = call i32 @putchar(i32 10)
br i1 %4, label %45, label %26
26: ; preds = %24
%27 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%28 = call i8* @llvm.stacksave()
%29 = alloca i8, i64 %1
%30 = load i32, i32* @stdin
%31 = call i8* @fgetpass(i8* %29, i64 %1, i32 %30)
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %42
33: ; preds = %26
%34 = load i32, i32* @stdout
%35 = call i32 @fflush(i32 %34)
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i64 %1)
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %26
%43 = call i32 @putchar(i32 10)
%44 = call i32 @strncmp(i8* %0, i8* %29, i64 %1)
br label %45
45: ; preds = %42, %24
%46 = phi i32 [ %44, %42 ], [ %6, %24 ]
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %5
48: ; preds = %45
ret void
}