#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*/ printf(char *);
int /*<<< orphan*/ stdin;
size_t strlen(char *);
void goodG2B() {
  char *password;
  char passwordBuffer[100] = "";
  char *epasswd = (char *)alloca(100 * sizeof(char));
  password = passwordBuffer;
  {
    size_t passwordLen = 0;
    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);
    }
  }
}


x86 assembly (clang, -O0):
<goodG2B>:
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   1080 <alloca@plt>
mov    %rax,-0x78(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x8(%rbp)
movq   $0x0,-0x80(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e34(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    11dd <goodG2B+0x6d>
lea    0xe2f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
jbe    1205 <goodG2B+0x95>
mov    -0x8(%rbp),%rax
mov    -0x80(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   1030 <crypt@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    123a <goodG2B+0xca>
lea    0xde8(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<goodG2B>:
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   1070 <alloca@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
test   %rax,%rax
jne    11c2 <goodG2B+0x62>
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
movb   $0x0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
je     11d7 <goodG2B+0x77>
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xe22(%rip),%rsi
mov    %rsp,%rdi
call   1040 <crypt@plt>
test   %rax,%rax
je     11f1 <goodG2B+0x91>
add    $0x70,%rsp
pop    %rbx
ret
lea    0xe0b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [3 x i8] c"ab\00"
@str = [12 x i8] c"crypt error\00"
@str.3 = [15 x i8] c"fgets() failed\00"
define void @goodG2B() {
%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.3, 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.1, 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
ret void
}