#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*/ printf(char *);
int /*<<< orphan*/ strcpy(char *, char *);
void CWE259_Hard_Coded_Password__w32_char_01_bad() {
  char *password;
  char passwordBuffer[100] = "";
  char *epasswd = (char *)alloca(100 * sizeof(char));
  password = passwordBuffer;
  strcpy(password, "ABCD1234!");
  {
    epasswd = crypt(password, "ab");
    if (epasswd == NULL) {
      printf("crypt error\n");
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<CWE259_Hard_Coded_Password__w32_char_01_bad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
mov    $0x64,%edi
call   1070 <alloca@plt>
mov    %rax,-0x78(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1040 <crypt@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    11d6 <CWE259_Hard_Coded_Password__w32_char_01_bad+0x76>
lea    0xe46(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CWE259_Hard_Coded_Password__w32_char_01_bad>:
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   1060 <alloca@plt>
lea    0xe72(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe6a(%rip),%rsi
mov    %rbx,%rdi
call   1050 <crypt@plt>
test   %rax,%rax
je     11b3 <CWE259_Hard_Coded_Password__w32_char_01_bad+0x63>
add    $0x70,%rsp
pop    %rbx
ret
lea    0xe53(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"ABCD1234!\00"
@.str.1 = [3 x i8] c"ab\00"
@.str.2 = [13 x i8] c"crypt error\0A\00"
define void @CWE259_Hard_Coded_Password__w32_char_01_bad() {
%1 = alloca i8*
%2 = alloca [100 x i8]
%3 = alloca i8*
%4 = bitcast [100 x i8]* %2 to i8*
%5 = call i64 @alloca(i32 100)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %3
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
store i8* %7, i8** %1
%8 = load i8*, i8** %1
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%10 = load i8*, i8** %1
%11 = call i8* @crypt(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"ABCD1234!\00"
@.str.1 = [3 x i8] c"ab\00"
@str = [12 x i8] c"crypt error\00"
define void @CWE259_Hard_Coded_Password__w32_char_01_bad() {
%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 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = call i8* @crypt(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
ret void
}