#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*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ gets_quiet(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int get_password(char *password, int len) {
  char pw1[1024], pw2[1024];
  printf("Password: ");
  if (gets_quiet(pw1, 1024)) {
    fprintf(stderr, "Error: Empty password.\n");
    return 1;
  }
  printf("\n");
  printf("Reenter password: ");
  if (gets_quiet(pw2, 1024)) {
    fprintf(stderr, "Error: Empty password.\n");
    return 1;
  }
  printf("\n");
  if (strcmp(pw1, pw2)) {
    fprintf(stderr, "Error: Passwords do not match.\n");
    return 1;
  }
  strncpy(password, pw1, len);
  return 0;
}


x86 assembly (clang, -O0):
<get_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1050 <gets_quiet@plt>
cmp    $0x0,%rax
je     11aa <get_password+0x5a>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1262 <get_password+0x112>
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
lea    -0x820(%rbp),%rdi
mov    $0x400,%esi
call   1050 <gets_quiet@plt>
cmp    $0x0,%rax
je     11fe <get_password+0xae>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1262 <get_password+0x112>
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
lea    -0x420(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1248 <get_password+0xf8>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1262 <get_password+0x112>
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_password>:
push   %rbp
push   %rbx
sub    $0x808,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe8b(%rip),%rdi
call   1050 <printf@plt>
mov    %rsp,%rdi
mov    $0x400,%esi
call   1060 <gets_quiet@plt>
test   %rax,%rax
jne    11b9 <get_password+0x59>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe86(%rip),%rdi
call   1050 <printf@plt>
lea    0x400(%rsp),%rdi
mov    $0x400,%esi
call   1060 <gets_quiet@plt>
test   %rax,%rax
je     11dd <get_password+0x7d>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%eax
add    $0x808,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rsp,%rdi
lea    0x400(%rsp),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     120e <get_password+0xae>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
jmp    11c9 <get_password+0x69>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <strncpy@plt>
xor    %eax,%eax
jmp    11d3 <get_password+0x73>

LLVM IR (-O0):
@.str = [11 x i8] c"Password: \00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Error: Empty password.\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [19 x i8] c"Reenter password: \00"
@.str.4 = [32 x i8] c"Error: Passwords do not match.\0A\00"
define i32 @get_password(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = call i64 @gets_quiet(i8* %9, i32 1024)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %38
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%19 = call i64 @gets_quiet(i8* %18, i32 1024)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %38
24: ; preds = %15
%25 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%28 = call i64 @strcmp(i8* %26, i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %38
33: ; preds = %24
%34 = load i8*, i8** %4
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%36 = load i32, i32* %5
%37 = call i32 @strncpy(i8* %34, i8* %35, i32 %36)
store i32 0, i32* %3
br label %38
38: ; preds = %33, %30, %21, %12
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [11 x i8] c"Password: \00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"Error: Empty password.\0A\00"
@.str.3 = [19 x i8] c"Reenter password: \00"
@.str.4 = [32 x i8] c"Error: Passwords do not match.\0A\00"
define i32 @get_password(i8* %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = call i64 @gets_quiet(i8* %5, i32 1024)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %30
13: ; preds = %2
%14 = call i32 @putchar(i32 10)
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%16 = call i64 @gets_quiet(i8* %6, i32 1024)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %30
21: ; preds = %13
%22 = call i32 @putchar(i32 10)
%23 = call i64 @strcmp(i8* %5, i8* %6)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %30
28: ; preds = %21
%29 = call i32 @strncpy(i8* %0, i8* %5, i32 %1)
br label %30
30: ; preds = %28, %25, %18, %10
%31 = phi i32 [ 1, %10 ], [ 1, %18 ], [ 1, %25 ], [ 0, %28 ]
ret i32 %31
}