#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int check_forbidden_characters(char *, char *);
int check_string_empty(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *);
char *getenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ web_s_authentication();
void *web_c_authentication(void) {
  FILE *login;
  char *usr = NULL, *pw = NULL, *forbidden = ".,;:";
  usr = getenv("WWW_Username");
  pw = getenv("WWW_Password");
  if (usr == NULL || check_string_empty(usr) == 1 || pw == NULL ||
      check_string_empty(pw) == 1) {
    perror("Error getting username");
    web_s_authentication();
    return NULL;
  }
  if (check_forbidden_characters(usr, forbidden) == 1 ||
      check_forbidden_characters(pw, forbidden) == 1) {
    perror("Forbidden characters in username or password");
    web_s_authentication();
    return NULL;
  }
  login = fopen("/tmp/new_login", "w+");
  if (login == NULL) {
    perror("Error opening loginfile");
    web_s_authentication();
    return NULL;
  }
  fprintf(login, "%s:%s\n", usr, pw);
  fclose(login);
  sleep(1);
  web_s_authentication();
  return NULL;
}


x86 assembly (clang, -O0):
<web_c_authentication>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe51(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe4b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
lea    0xe48(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     120d <web_c_authentication+0x7d>
mov    -0x18(%rbp),%rdi
call   1080 <check_string_empty@plt>
cmp    $0x1,%eax
je     120d <web_c_authentication+0x7d>
cmpq   $0x0,-0x20(%rbp)
je     120d <web_c_authentication+0x7d>
mov    -0x20(%rbp),%rdi
call   1080 <check_string_empty@plt>
cmp    $0x1,%eax
jne    122d <web_c_authentication+0x9d>
lea    0xe0b(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x0,%al
call   1050 <web_s_authentication@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f5 <web_c_authentication+0x165>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <check_forbidden_characters@plt>
cmp    $0x1,%eax
je     1259 <web_c_authentication+0xc9>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <check_forbidden_characters@plt>
cmp    $0x1,%eax
jne    1279 <web_c_authentication+0xe9>
lea    0xdd6(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x0,%al
call   1050 <web_s_authentication@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f5 <web_c_authentication+0x165>
lea    0xde3(%rip),%rdi
lea    0xdeb(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    12bb <web_c_authentication+0x12b>
lea    0xdd3(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x0,%al
call   1050 <web_s_authentication@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f5 <web_c_authentication+0x165>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdbf(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    $0x0,%al
call   1050 <web_s_authentication@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<web_c_authentication>:
push   %r15
push   %r14
push   %rbx
lea    0xe69(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
lea    0xe67(%rip),%rdi
call   1030 <getenv@plt>
test   %r14,%r14
je     125c <web_c_authentication+0xcc>
mov    %rax,%r15
mov    %r14,%rdi
call   1080 <check_string_empty@plt>
test   %r15,%r15
je     125c <web_c_authentication+0xcc>
cmp    $0x1,%eax
je     125c <web_c_authentication+0xcc>
mov    %r15,%rdi
call   1080 <check_string_empty@plt>
cmp    $0x1,%eax
je     125c <web_c_authentication+0xcc>
lea    0xe16(%rip),%rsi
mov    %r14,%rdi
call   1060 <check_forbidden_characters@plt>
cmp    $0x1,%eax
je     126a <web_c_authentication+0xda>
lea    0xe02(%rip),%rsi
mov    %r15,%rdi
call   1060 <check_forbidden_characters@plt>
cmp    $0x1,%eax
je     126a <web_c_authentication+0xda>
lea    0xe51(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1278 <web_c_authentication+0xe8>
mov    %rax,%rbx
lea    0xe60(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
xor    %eax,%eax
call   1050 <web_s_authentication@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdbc(%rip),%rdi
call   10a0 <perror@plt>
jmp    124d <web_c_authentication+0xbd>
lea    0xdc5(%rip),%rdi
call   10a0 <perror@plt>
jmp    124d <web_c_authentication+0xbd>
lea    0xdf6(%rip),%rdi
call   10a0 <perror@plt>
jmp    124d <web_c_authentication+0xbd>

LLVM IR (-O0):
@.str = [5 x i8] c".,;:\00"
@.str.1 = [13 x i8] c"WWW_Username\00"
@.str.2 = [13 x i8] c"WWW_Password\00"
@.str.3 = [23 x i8] c"Error getting username\00"
@.str.4 = [45 x i8] c"Forbidden characters in username or password\00"
@.str.5 = [15 x i8] c"/tmp/new_login\00"
@.str.6 = [3 x i8] c"w+\00"
@.str.7 = [24 x i8] c"Error opening loginfile\00"
@.str.8 = [7 x i8] c"%s:%s\0A\00"
define i8* @web_c_authentication() {
%1 = alloca i8*
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* null, i8** %3
store i8* null, i8** %4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i8* %6, i8** %3
%7 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i8* %7, i8** %4
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %21, label %10
10: ; preds = %0
%11 = load i8*, i8** %3
%12 = call i32 @check_string_empty(i8* %11)
%13 = icmp eq i32 %12, 1
br i1 %13, label %21, label %14
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = call i32 @check_string_empty(i8* %18)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %24
21: ; preds = %17, %14, %10, %0
%22 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 (...) @web_s_authentication()
store i8* null, i8** %1
br label %53
24: ; preds = %17
%25 = load i8*, i8** %3
%26 = load i8*, i8** %5
%27 = call i32 @check_forbidden_characters(i8* %25, i8* %26)
%28 = icmp eq i32 %27, 1
br i1 %28, label %34, label %29
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = load i8*, i8** %5
%32 = call i32 @check_forbidden_characters(i8* %30, i8* %31)
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %37
34: ; preds = %29, %24
%35 = call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 (...) @web_s_authentication()
store i8* null, i8** %1
br label %53
37: ; preds = %29
%38 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %38, i32** %2
%39 = load i32*, i32** %2
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%43 = call i32 (...) @web_s_authentication()
store i8* null, i8** %1
br label %53
44: ; preds = %37
%45 = load i32*, i32** %2
%46 = load i8*, i8** %3
%47 = load i8*, i8** %4
%48 = call i32 @fprintf(i32* %45, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* %46, i8* %47)
%49 = load i32*, i32** %2
%50 = call i32 @fclose(i32* %49)
%51 = call i32 @sleep(i32 1)
%52 = call i32 (...) @web_s_authentication()
store i8* null, i8** %1
br label %53
53: ; preds = %44, %41, %34, %21
%54 = load i8*, i8** %1
ret i8* %54
}

LLVM IR (-O2):
@.str = [5 x i8] c".,;:\00"
@.str.1 = [13 x i8] c"WWW_Username\00"
@.str.2 = [13 x i8] c"WWW_Password\00"
@.str.3 = [23 x i8] c"Error getting username\00"
@.str.4 = [45 x i8] c"Forbidden characters in username or password\00"
@.str.5 = [15 x i8] c"/tmp/new_login\00"
@.str.6 = [3 x i8] c"w+\00"
@.str.7 = [24 x i8] c"Error opening loginfile\00"
@.str.8 = [7 x i8] c"%s:%s\0A\00"
define noalias i8* @web_c_authentication() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%3 = icmp eq i8* %1, null
br i1 %3, label %12, label %4
4: ; preds = %0
%5 = tail call i32 @check_string_empty(i8* %1)
%6 = icmp eq i32 %5, 1
%7 = icmp eq i8* %2, null
%8 = or i1 %7, %6
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = tail call i32 @check_string_empty(i8* %2)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %9, %4, %0
%13 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %31
14: ; preds = %9
%15 = tail call i32 @check_forbidden_characters(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32 %15, 1
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = tail call i32 @check_forbidden_characters(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %22
20: ; preds = %17, %14
%21 = tail call i32 @perror(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
br label %31
22: ; preds = %17
%23 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
br label %31
27: ; preds = %22
%28 = tail call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* %1, i8* %2)
%29 = tail call i32 @fclose(i32* %23)
%30 = tail call i32 @sleep(i32 1)
br label %31
31: ; preds = %27, %25, %20, %12
%32 = tail call i32 (...) @web_s_authentication()
ret i8* null
}