#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 fdgetc(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *malloc(int);
int /*<<< orphan*/ stderr;
char *xrealloc(char *, size_t, size_t);
char *passphrase_read2(int fdin, int flags) {
  char *rc = malloc(32 * sizeof(char));
  size_t size = 32;
  size_t len = 0;
  int c;
  if (rc == NULL)
    return NULL;
  for (;;) {
    c = fdgetc(fdin);
    if ((c < 0) || (c == '\n')) {
      break;
    }
    if (c == 0)
      continue;
    do {
      do {
        ;
      } while (0);
      *(rc + len++) = (char)c;
      do {
        ;
      } while (0);
    } while (0);
    do {
      fflush(stderr);
    } while (0);
    if (len == size) {
      if ((rc = xrealloc(rc, (size_t)size, (size_t)size << 1)) == NULL)
        return NULL;
      size <<= 1L;
    }
  }
  *(rc + len) = 0;
  fprintf(stderr, "\n");
  return rc;
  (void)flags;
}


x86 assembly (clang, -O0):
<passphrase_read2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    $0x20,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x20,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1194 <passphrase_read2+0x44>
movq   $0x0,-0x8(%rbp)
jmp    128b <passphrase_read2+0x13b>
jmp    1199 <passphrase_read2+0x49>
mov    -0xc(%rbp),%edi
call   1040 <fdgetc@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     11b8 <passphrase_read2+0x68>
cmpl   $0xa,-0x2c(%rbp)
jne    11bd <passphrase_read2+0x6d>
jmp    1262 <passphrase_read2+0x112>
cmpl   $0x0,-0x2c(%rbp)
jne    11cc <passphrase_read2+0x7c>
jmp    1199 <passphrase_read2+0x49>
jmp    11d1 <passphrase_read2+0x81>
jmp    11d6 <passphrase_read2+0x86>
jmp    11db <passphrase_read2+0x8b>
mov    -0x2c(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x28(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    11fb <passphrase_read2+0xab>
jmp    1200 <passphrase_read2+0xb0>
jmp    1205 <passphrase_read2+0xb5>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    125d <passphrase_read2+0x10d>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rdx
shl    $0x1,%rdx
call   1030 <xrealloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1251 <passphrase_read2+0x101>
movq   $0x0,-0x8(%rbp)
jmp    128b <passphrase_read2+0x13b>
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1199 <passphrase_read2+0x49>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    0xd82(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<passphrase_read2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x20,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11ee <passphrase_read2+0x9e>
mov    %rax,%r14
mov    $0x20,%r12d
xor    %r15d,%r15d
mov    0x2e5d(%rip),%rbp
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1040 <fdgetc@plt>
test   %eax,%eax
js     11d5 <passphrase_read2+0x85>
cmp    $0xa,%eax
je     11d5 <passphrase_read2+0x85>
test   %eax,%eax
je     1190 <passphrase_read2+0x40>
mov    %al,(%r14,%r13,1)
add    $0x1,%r13
mov    0x0(%rbp),%edi
call   1070 <fflush@plt>
cmp    %r12,%r13
jne    1190 <passphrase_read2+0x40>
lea    (%r12,%r12,1),%rdx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rdx,%r12
call   1030 <xrealloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1190 <passphrase_read2+0x40>
jmp    11f1 <passphrase_read2+0xa1>
movb   $0x0,(%r14,%r13,1)
mov    0x0(%rbp),%edi
lea    0xe1c(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r14,%r15
jmp    11f1 <passphrase_read2+0xa1>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [2 x i8] c"\0A\00"
define i8* @passphrase_read2(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%10 = call i8* @malloc(i32 32)
store i8* %10, i8** %6
store i64 32, i64* %7
store i64 0, i64* %8
%11 = load i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i8* null, i8** %3
br label %67
14: ; preds = %2
br label %15
15: ; preds = %59, %27, %14
%16 = load i32, i32* %4
%17 = call i32 @fdgetc(i32 %16)
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = icmp slt i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = load i32, i32* %9
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %20, %15
br label %60
24: ; preds = %20
%25 = load i32, i32* %9
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %24
br label %15
28: ; preds = %24
br label %29
29: ; preds = %28
br label %30
30: ; preds = %29
br label %31
31: ; preds = %30
%32 = load i32, i32* %9
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %6
%35 = load i64, i64* %8
%36 = add i64 %35, 1
store i64 %36, i64* %8
%37 = getelementptr inbounds i8, i8* %34, i64 %35
store i8 %33, i8* %37
br label %38
38: ; preds = %31
br label %39
39: ; preds = %38
br label %40
40: ; preds = %39
br label %41
41: ; preds = %40
%42 = load i32, i32* @stderr
%43 = call i32 @fflush(i32 %42)
br label %44
44: ; preds = %41
%45 = load i64, i64* %8
%46 = load i64, i64* %7
%47 = icmp eq i64 %45, %46
br i1 %47, label %48, label %59
48: ; preds = %44
%49 = load i8*, i8** %6
%50 = load i64, i64* %7
%51 = load i64, i64* %7
%52 = shl i64 %51, 1
%53 = call i8* @xrealloc(i8* %49, i64 %50, i64 %52)
store i8* %53, i8** %6
%54 = icmp eq i8* %53, null
br i1 %54, label %55, label %56
55: ; preds = %48
store i8* null, i8** %3
br label %67
56: ; preds = %48
%57 = load i64, i64* %7
%58 = shl i64 %57, 1
store i64 %58, i64* %7
br label %59
59: ; preds = %56, %44
br label %15
60: ; preds = %23
%61 = load i8*, i8** %6
%62 = load i64, i64* %8
%63 = getelementptr inbounds i8, i8* %61, i64 %62
store i8 0, i8* %63
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%66 = load i8*, i8** %6
store i8* %66, i8** %3
br label %67
67: ; preds = %60, %55, %13
%68 = load i8*, i8** %3
ret i8* %68
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [2 x i8] c"\0A\00"
define i8* @passphrase_read2(i32 %0, i32 %1) {
%3 = tail call dereferenceable_or_null(32) i8* @malloc(i32 32)
%4 = icmp eq i8* %3, null
br i1 %4, label %33, label %5
5: ; preds = %2, %25
%6 = phi i8* [ %27, %25 ], [ %3, %2 ]
%7 = phi i64 [ %26, %25 ], [ 32, %2 ]
%8 = phi i64 [ %20, %25 ], [ 0, %2 ]
br label %9
9: ; preds = %5, %18
%10 = phi i64 [ %20, %18 ], [ %8, %5 ]
br label %11
11: ; preds = %9, %16
%12 = tail call i32 @fdgetc(i32 %0)
%13 = icmp slt i32 %12, 0
%14 = icmp eq i32 %12, 10
%15 = or i1 %13, %14
br i1 %15, label %29, label %16
16: ; preds = %11
%17 = icmp eq i32 %12, 0
br i1 %17, label %11, label %18
18: ; preds = %16
%19 = trunc i32 %12 to i8
%20 = add i64 %10, 1
%21 = getelementptr inbounds i8, i8* %6, i64 %10
store i8 %19, i8* %21
%22 = load i32, i32* @stderr
%23 = tail call i32 @fflush(i32 %22)
%24 = icmp eq i64 %20, %7
br i1 %24, label %25, label %9
25: ; preds = %18
%26 = shl i64 %7, 1
%27 = tail call i8* @xrealloc(i8* %6, i64 %7, i64 %26)
%28 = icmp eq i8* %27, null
br i1 %28, label %33, label %5
29: ; preds = %11
%30 = getelementptr inbounds i8, i8* %6, i64 %10
store i8 0, i8* %30
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %25, %2, %29
%34 = phi i8* [ %6, %29 ], [ null, %2 ], [ null, %25 ]
ret i8* %34
}