#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 */
struct termios {
  int /*<<< orphan*/ c_lflag;
};

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
scalar_t__ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ write(int, char *, int);
int mpb_create_passwd(void) {
  int i = 0;
  int fd = -1;
  char tmp_passwd[16] = {'\0'};
  char mpb_passwd1[16] = {'\0'};
  char mpb_passwd2[16] = {'\0'};
  struct termios mpb_initialrsettings;
  struct termios mpb_newrsettings;
  fd = open("./.passwd", O_RDWR | O_CREAT, 0664);
  if (fd < 0) {
    perror("log_in.c mpb_create_passwd open()");
    exit(1);
  }
  tcgetattr(fileno(stdin), &mpb_initialrsettings);
  mpb_newrsettings = mpb_initialrsettings;
  mpb_newrsettings.c_lflag &= ~ECHO;
  if (0 != tcsetattr(fileno(stdin), TCSAFLUSH, &mpb_newrsettings)) {
    fprintf(stderr, "Could not set attributes\n");
  } else {
    i = 0;
    do {
      fprintf(stdout, "\nEnter password: ");
      memset(mpb_passwd1, 0, 16);
      fgets(mpb_passwd1, 16, stdin);
      fprintf(stdout, "\nAgain input: ");
      memset(mpb_passwd2, 0, 16);
      fgets(mpb_passwd2, 16, stdin);
      i++;
    } while ((0 != strcmp(mpb_passwd1, mpb_passwd2)) && (i < 3));
    tcsetattr(fileno(stdin), TCSANOW, &mpb_initialrsettings);
  }
  if (i < 3) {
    write(fd, mpb_passwd1, 16);
    printf("\n"
           "\033[37m"
           "create passwd success"
           "\033[0m"
           "\n");
    close(fd);
    return 0;
  } else {
    printf("\n"
           "\033[31m"
           "error create passwd"
           "\033[0m"
           "\n");
    close(fd);
    return 1;
  }
}


x86 assembly (clang, -O0):
<mpb_create_passwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
mov    0x2dd2(%rip),%rax
or     (%rax),%esi
lea    0xdd1(%rip),%rdi
mov    $0x1b4,%edx
call   10d0 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    125c <mpb_create_passwd+0x8c>
lea    0xdbd(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
call   10a0 <fileno@plt>
mov    %eax,%edi
lea    -0x48(%rbp),%rsi
call   10b0 <tcgetattr@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x50(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
call   10a0 <fileno@plt>
mov    %eax,%edi
mov    0x2d34(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   10c0 <tcsetattr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12d7 <mpb_create_passwd+0x107>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
lea    0xd5f(%rip),%rsi
call   1090 <fprintf@plt>
jmp    13b6 <mpb_create_passwd+0x1e6>
movl   $0x0,-0x8(%rbp)
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
lea    0xd58(%rip),%rsi
call   1090 <fprintf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    -0x30(%rbp),%rdi
mov    0x2cc2(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%esi
call   1070 <fgets@plt>
mov    0x2c87(%rip),%rax
mov    (%rax),%edi
lea    0xd2e(%rip),%rsi
call   1090 <fprintf@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    -0x40(%rbp),%rdi
mov    0x2c86(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%esi
call   1070 <fgets@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <strcmp@plt>
mov    %rax,%rdx
xor    %eax,%eax
xor    %ecx,%ecx
cmp    %rdx,%rcx
mov    %al,-0x51(%rbp)
je     1389 <mpb_create_passwd+0x1b9>
cmpl   $0x3,-0x8(%rbp)
setl   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    12de <mpb_create_passwd+0x10e>
mov    0x2c35(%rip),%rax
mov    (%rax),%edi
call   10a0 <fileno@plt>
mov    %eax,%edi
mov    0x2c1d(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   10c0 <tcsetattr@plt>
cmpl   $0x3,-0x8(%rbp)
jge    13f1 <mpb_create_passwd+0x221>
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
lea    0xc8f(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    140c <mpb_create_passwd+0x23c>
lea    0xc90(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpb_create_passwd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
mov    0x2dee(%rip),%rax
mov    0x2dff(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xdfc(%rip),%rdi
mov    $0x1b4,%edx
call   10d0 <open@plt>
test   %eax,%eax
js     1382 <mpb_create_passwd+0x1b2>
mov    %eax,%ebp
mov    0x2db1(%rip),%r13
mov    0x0(%r13),%edi
call   10a0 <fileno@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   10b0 <tcgetattr@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
not    %eax
and    (%rsp),%eax
mov    %eax,0x8(%rsp)
mov    0x0(%r13),%edi
call   10a0 <fileno@plt>
mov    0x2d84(%rip),%rcx
mov    (%rcx),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   10c0 <tcsetattr@plt>
test   %rax,%rax
je     1281 <mpb_create_passwd+0xb1>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    0xdb5(%rip),%rsi
call   1090 <fprintf@plt>
jmp    133d <mpb_create_passwd+0x16d>
mov    %ebp,0xc(%rsp)
xor    %eax,%eax
mov    0x2d1a(%rip),%r15
lea    0x10(%rsp),%rbp
lea    0xdbe(%rip),%r12
lea    0x20(%rsp),%rbx
nop
mov    %eax,%r14d
mov    (%r15),%edi
lea    0xd99(%rip),%rsi
call   1090 <fprintf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0x0(%r13),%edx
mov    %rbp,%rdi
mov    $0x10,%esi
call   1070 <fgets@plt>
mov    (%r15),%edi
mov    %r12,%rsi
call   1090 <fprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x10,%esi
call   1070 <fgets@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1317 <mpb_create_passwd+0x147>
lea    0x1(%r14),%eax
cmp    $0x2,%r14d
jb     12a0 <mpb_create_passwd+0xd0>
mov    0x0(%r13),%edi
call   10a0 <fileno@plt>
mov    0x2ca1(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   10c0 <tcsetattr@plt>
cmp    $0x1,%r14d
mov    0xc(%rsp),%ebp
ja     1374 <mpb_create_passwd+0x1a4>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x10,%edx
call   1040 <write@plt>
xor    %ebx,%ebx
lea    0xd2e(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebx
lea    0xce7(%rip),%rdi
jmp    1357 <mpb_create_passwd+0x187>
lea    0xc81(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [10 x i8] c"./.passwd\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [34 x i8] c"log_in.c mpb_create_passwd open()\00"
@stdin = global i32 0
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@stderr = global i32 0
@.str.2 = [26 x i8] c"Could not set attributes\0A\00"
@stdout = global i32 0
@.str.3 = [18 x i8] c"\0AEnter password: \00"
@.str.4 = [15 x i8] c"\0AAgain input: \00"
@TCSANOW = global i32 0
@.str.5 = [33 x i8] c"\0A\1B[37mcreate passwd success\1B[0m\0A\00"
@.str.6 = [31 x i8] c"\0A\1B[31merror create passwd\1B[0m\0A\00"
define i32 @mpb_create_passwd() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = alloca [16 x i8]
%7 = alloca %struct.termios
%8 = alloca %struct.termios
store i32 0, i32* %2
store i32 -1, i32* %3
%9 = bitcast [16 x i8]* %4 to i8*
%10 = bitcast [16 x i8]* %5 to i8*
%11 = bitcast [16 x i8]* %6 to i8*
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_CREAT
%14 = or i32 %12, %13
%15 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %14, i32 436)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %0
%19 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %0
%22 = load i32, i32* @stdin
%23 = call i32 @fileno(i32 %22)
%24 = call i32 @tcgetattr(i32 %23, %struct.termios* %7)
%25 = bitcast %struct.termios* %8 to i8*
%26 = bitcast %struct.termios* %7 to i8*
%27 = load i32, i32* @ECHO
%28 = xor i32 %27, -1
%29 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%30 = load i32, i32* %29
%31 = and i32 %30, %28
store i32 %31, i32* %29
%32 = load i32, i32* @stdin
%33 = call i32 @fileno(i32 %32)
%34 = load i32, i32* @TCSAFLUSH
%35 = call i64 @tcsetattr(i32 %33, i32 %34, %struct.termios* %8)
%36 = icmp ne i64 0, %35
br i1 %36, label %37, label %40
37: ; preds = %21
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %73
40: ; preds = %21
store i32 0, i32* %2
br label %41
41: ; preds = %66, %40
%42 = load i32, i32* @stdout
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%44 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%45 = call i32 @memset(i8* %44, i32 0, i32 16)
%46 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%47 = load i32, i32* @stdin
%48 = call i32 @fgets(i8* %46, i32 16, i32 %47)
%49 = load i32, i32* @stdout
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%51 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%52 = call i32 @memset(i8* %51, i32 0, i32 16)
%53 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%54 = load i32, i32* @stdin
%55 = call i32 @fgets(i8* %53, i32 16, i32 %54)
%56 = load i32, i32* %2
%57 = add nsw i32 %56, 1
store i32 %57, i32* %2
br label %58
58: ; preds = %41
%59 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%60 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%61 = call i64 @strcmp(i8* %59, i8* %60)
%62 = icmp ne i64 0, %61
br i1 %62, label %63, label %66
63: ; preds = %58
%64 = load i32, i32* %2
%65 = icmp slt i32 %64, 3
br label %66
66: ; preds = %63, %58
%67 = phi i1 [ false, %58 ], [ %65, %63 ]
br i1 %67, label %41, label %68
68: ; preds = %66
%69 = load i32, i32* @stdin
%70 = call i32 @fileno(i32 %69)
%71 = load i32, i32* @TCSANOW
%72 = call i64 @tcsetattr(i32 %70, i32 %71, %struct.termios* %7)
br label %73
73: ; preds = %68, %37
%74 = load i32, i32* %2
%75 = icmp slt i32 %74, 3
br i1 %75, label %76, label %83
76: ; preds = %73
%77 = load i32, i32* %3
%78 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%79 = call i32 @write(i32 %77, i8* %78, i32 16)
%80 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%81 = load i32, i32* %3
%82 = call i32 @close(i32 %81)
store i32 0, i32* %1
br label %87
83: ; preds = %73
%84 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
%85 = load i32, i32* %3
%86 = call i32 @close(i32 %85)
store i32 1, i32* %1
br label %87
87: ; preds = %83, %76
%88 = load i32, i32* %1
ret i32 %88
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [10 x i8] c"./.passwd\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [34 x i8] c"log_in.c mpb_create_passwd open()\00"
@stdin = global i32 0
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@stderr = global i32 0
@.str.2 = [26 x i8] c"Could not set attributes\0A\00"
@stdout = global i32 0
@.str.3 = [18 x i8] c"\0AEnter password: \00"
@.str.4 = [15 x i8] c"\0AAgain input: \00"
@TCSANOW = global i32 0
@str = [30 x i8] c"\0A\1B[31merror create passwd\1B[0m\00"
@str.7 = [32 x i8] c"\0A\1B[37mcreate passwd success\1B[0m\00"
define i32 @mpb_create_passwd() {
%1 = alloca [16 x i8]
%2 = alloca [16 x i8]
%3 = alloca %struct.termios
%4 = alloca %struct.termios
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%7 = bitcast %struct.termios* %3 to i8*
%8 = bitcast %struct.termios* %4 to i8*
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_CREAT
%11 = or i32 %10, %9
%12 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11, i32 436)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = load i32, i32* @stdin
%19 = tail call i32 @fileno(i32 %18)
%20 = call i32 @tcgetattr(i32 %19, %struct.termios* %3)
%21 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%22 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%23 = load i32, i32* %21
%24 = load i32, i32* @ECHO
%25 = xor i32 %24, -1
%26 = and i32 %23, %25
store i32 %26, i32* %22
%27 = load i32, i32* @stdin
%28 = call i32 @fileno(i32 %27)
%29 = load i32, i32* @TCSAFLUSH
%30 = call i64 @tcsetattr(i32 %28, i32 %29, %struct.termios* %4)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %17
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %57
35: ; preds = %17, %35
%36 = phi i32 [ %47, %35 ], [ 0, %17 ]
%37 = load i32, i32* @stdout
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 @memset(i8* %5, i32 0, i32 16)
%40 = load i32, i32* @stdin
%41 = call i32 @fgets(i8* %5, i32 16, i32 %40)
%42 = load i32, i32* @stdout
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%44 = call i32 @memset(i8* %6, i32 0, i32 16)
%45 = load i32, i32* @stdin
%46 = call i32 @fgets(i8* %6, i32 16, i32 %45)
%47 = add nuw nsw i32 %36, 1
%48 = call i64 @strcmp(i8* %5, i8* %6)
%49 = icmp ne i64 %48, 0
%50 = icmp ult i32 %36, 2
%51 = select i1 %49, i1 %50, i1 false
br i1 %51, label %35, label %52
52: ; preds = %35
%53 = load i32, i32* @stdin
%54 = call i32 @fileno(i32 %53)
%55 = load i32, i32* @TCSANOW
%56 = call i64 @tcsetattr(i32 %54, i32 %55, %struct.termios* %3)
br i1 %50, label %57, label %59
57: ; preds = %32, %52
%58 = call i32 @write(i32 %12, i8* %5, i32 16)
br label %59
59: ; preds = %52, %57
%60 = phi i8* [ getelementptr inbounds ([32 x i8], [32 x i8]* @str.7, i64 0, i64 0), %57 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0), %52 ]
%61 = phi i32 [ 0, %57 ], [ 1, %52 ]
%62 = call i32 @puts(i8* dereferenceable(1) %60)
%63 = call i32 @close(i32 %12)
ret i32 %61
}