#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 */
scalar_t__ alloca(int);
char *crypt(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
size_t strlen(char *);
void good1() {
  {
    char password[100] = "";
    char *epasswd = (char *)alloca(100 * sizeof(char));
    size_t passwordLen = 0;
    char *username = "User";
    char *domain = "Domain";
    if (fgets(password, 100, stdin) == NULL) {
      printf("fgets() failed\n");
      password[0] = '\0';
    }
    passwordLen = strlen(password);
    if (passwordLen > 0) {
      password[passwordLen - 1] = '\0';
    }
    epasswd = crypt(password, "ab");
    if (epasswd == NULL) {
      printf("crypt error\n");
      exit(1);
    }
    printf("passwd=%s, epasswd=%s\n", password, epasswd);
    fprintf(stderr, "User attempted access\n");
  }
}


x86 assembly (clang, -O0):
<good1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
mov    $0x64,%edi
call   1090 <alloca@plt>
mov    %rax,-0x78(%rbp)
movq   $0x0,-0x80(%rbp)
lea    0xe48(%rip),%rax
mov    %rax,-0x88(%rbp)
lea    0xe3f(%rip),%rax
mov    %rax,-0x90(%rbp)
lea    -0x70(%rbp),%rdi
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    1200 <good1+0x80>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movb   $0x0,-0x70(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
jbe    1225 <good1+0xa5>
mov    -0x80(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   1030 <crypt@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    125c <good1+0xdc>
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x70(%rbp),%rsi
mov    -0x78(%rbp),%rdx
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
call   1080 <fprintf@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<good1>:
push   %rbx
sub    $0x70,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
mov    $0x64,%edi
call   1090 <alloca@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x64,%esi
call   1070 <fgets@plt>
test   %rax,%rax
jne    11e2 <good1+0x62>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
movb   $0x0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
je     11f7 <good1+0x77>
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xe02(%rip),%rsi
mov    %rsp,%rdi
call   1040 <crypt@plt>
test   %rax,%rax
je     123a <good1+0xba>
lea    0xdf1(%rip),%rdi
mov    %rsp,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
call   1080 <fprintf@plt>
add    $0x70,%rsp
pop    %rbx
ret
lea    0xdf0(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"User\00"
@.str.1 = [7 x i8] c"Domain\00"
@stdin = global i32 0
@.str.2 = [16 x i8] c"fgets() failed\0A\00"
@.str.3 = [3 x i8] c"ab\00"
@.str.4 = [13 x i8] c"crypt error\0A\00"
@.str.5 = [23 x i8] c"passwd=%s, epasswd=%s\0A\00"
@stderr = global i32 0
@.str.6 = [23 x i8] c"User attempted access\0A\00"
define void @good1() {
%1 = alloca [100 x i8]
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = bitcast [100 x i8]* %1 to i8*
%7 = call i64 @alloca(i32 100)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %2
store i64 0, i64* %3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %5
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32* @fgets(i8* %9, i32 100, i32 %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
store i8 0, i8* %15
br label %16
16: ; preds = %13, %0
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%18 = call i64 @strlen(i8* %17)
store i64 %18, i64* %3
%19 = load i64, i64* %3
%20 = icmp ugt i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i64, i64* %3
%23 = sub i64 %22, 1
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %21, %16
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%27 = call i8* @crypt(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i8* %27, i8** %2
%28 = load i8*, i8** %2
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %25
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%35 = load i8*, i8** %2
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %34, i8* %35)
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.3 = [3 x i8] c"ab\00"
@.str.5 = [23 x i8] c"passwd=%s, epasswd=%s\0A\00"
@stderr = global i32 0
@.str.6 = [23 x i8] c"User attempted access\0A\00"
@str = [12 x i8] c"crypt error\00"
@str.7 = [15 x i8] c"fgets() failed\00"
define void @good1() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i64 @alloca(i32 100)
%4 = load i32, i32* @stdin
%5 = call i32* @fgets(i8* %2, i32 100, i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0))
store i8 0, i8* %2
br label %9
9: ; preds = %7, %0
%10 = call i64 @strlen(i8* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = add i64 %10, -1
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %13
store i8 0, i8* %14
br label %15
15: ; preds = %12, %9
%16 = call i8* @crypt(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %2, i8* %16)
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
ret void
}