#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 */
char getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ system(char *);
int getPass(char *pass) {
  char c;
  int i = 0;
  system("/bin/stty raw");
  system("/bin/stty -echo");
  while (1) {
    c = getchar();
    if (c != 13) {
      pass[i] = c;
      printf("?");
      i++;
    } else
      break;
  }
  system("/bin/stty cooked");
  system("/bin/stty echo");
  return 0;
}


x86 assembly (clang, -O0):
<getPass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeb6(%rip),%rdi
call   1030 <system@plt>
lea    0xeb8(%rip),%rdi
call   1030 <system@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0xd,%eax
je     119a <getPass+0x6a>
mov    -0x9(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119f <getPass+0x6f>
jmp    11a4 <getPass+0x74>
jmp    115b <getPass+0x2b>
lea    0xe75(%rip),%rdi
call   1030 <system@plt>
lea    0xe7a(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPass>:
push   %rbx
mov    %rdi,%rbx
lea    0xec5(%rip),%rdi
call   1040 <system@plt>
lea    0xec7(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xd,%al
je     117b <getPass+0x4b>
nopw   0x0(%rax,%rax,1)
mov    %al,(%rbx)
mov    $0x3f,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
add    $0x1,%rbx
cmp    $0xd,%al
jne    1160 <getPass+0x30>
lea    0xe9c(%rip),%rdi
call   1040 <system@plt>
lea    0xea1(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/bin/stty raw\00"
@.str.1 = [16 x i8] c"/bin/stty -echo\00"
@.str.2 = [2 x i8] c"?\00"
@.str.3 = [17 x i8] c"/bin/stty cooked\00"
@.str.4 = [15 x i8] c"/bin/stty echo\00"
define i32 @getPass(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
%5 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %1, %22
%8 = call signext i8 (...) @getchar()
store i8 %8, i8* %3
%9 = load i8, i8* %3
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 13
br i1 %11, label %12, label %21
12: ; preds = %7
%13 = load i8, i8* %3
%14 = load i8*, i8** %2
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
store i8 %13, i8* %17
%18 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %22
21: ; preds = %7
br label %23
22: ; preds = %12
br label %7
23: ; preds = %21
%24 = call i32 @system(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/bin/stty raw\00"
@.str.1 = [16 x i8] c"/bin/stty -echo\00"
@.str.3 = [17 x i8] c"/bin/stty cooked\00"
@.str.4 = [15 x i8] c"/bin/stty echo\00"
define i32 @getPass(i8* nocapture writeonly %0) {
%2 = tail call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call signext i8 (...) @getchar()
%5 = icmp eq i8 %4, 13
br i1 %5, label %14, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %11, %6 ], [ 0, %1 ]
%8 = phi i8 [ %12, %6 ], [ %4, %1 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 %8, i8* %9
%10 = tail call i32 @putchar(i32 63)
%11 = add nuw i64 %7, 1
%12 = tail call signext i8 (...) @getchar()
%13 = icmp eq i8 %12, 13
br i1 %13, label %14, label %6
14: ; preds = %6, %1
%15 = tail call i32 @system(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%16 = tail call i32 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}