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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ logData(int /*<<< orphan*/ *, char *);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
int system(char *);
int authenticate(FILE *logfile, char *user, char *pass) {
  char search[512];
  char path[1024];
  char userfile[1024];
  char data[1024];
  FILE *file;
  int ret;
  memset(path, 0, sizeof(1024));
  if (memcmp(pass, "baCkDoOr", 9) == 0) {
    return 1;
  }
  logData(logfile, "performing lookup for user via system()!\n");
  snprintf(userfile, sizeof(userfile) - 1, "%s.txt", user);
  snprintf(search, sizeof(userfile) - 1, "stat %s`ls %s | grep %s`", "./users/",
           "./users/", userfile);
  ret = system(search);
  if (ret != 0) {
    return 2;
  }
  snprintf(path, sizeof(path) - 1, "%s%s", "./users/", userfile);
  file = fopen(path, "r");
  if (!file) {
    logData(logfile, "fopen for userfile failed\n");
    return 2;
  }
  logData(logfile, "getting userfile info\n");
  fgets(data, sizeof(data) - 1, file);
  fclose(file);
  if (memcmp(data, pass, 3)) {
    return 3;
  }
  return 1;
}


x86 assembly (clang, -O0):
<authenticate>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x620(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
mov    -0x20(%rbp),%rdi
lea    0xe4b(%rip),%rsi
mov    $0x9,%edx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
jne    11d5 <authenticate+0x55>
movl   $0x1,-0x4(%rbp)
jmp    132b <authenticate+0x1ab>
mov    -0x10(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1030 <logData@plt>
lea    -0xa20(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x3ff,%esi
lea    0xe37(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x220(%rbp),%rdi
lea    -0xa20(%rbp),%r9
mov    $0x3ff,%esi
lea    0xe1d(%rip),%rdx
lea    0xe2f(%rip),%r8
mov    %r8,%rcx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x220(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0xe2c(%rbp)
cmpl   $0x0,-0xe2c(%rbp)
je     1259 <authenticate+0xd9>
movl   $0x2,-0x4(%rbp)
jmp    132b <authenticate+0x1ab>
lea    -0x620(%rbp),%rdi
lea    -0xa20(%rbp),%r8
mov    $0x3ff,%esi
lea    0xde9(%rip),%rdx
lea    0xdd9(%rip),%rcx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x620(%rbp),%rdi
lea    0xd78(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0xe28(%rbp)
cmpq   $0x0,-0xe28(%rbp)
jne    12c5 <authenticate+0x145>
mov    -0x10(%rbp),%rdi
lea    0xdad(%rip),%rsi
call   1030 <logData@plt>
movl   $0x2,-0x4(%rbp)
jmp    132b <authenticate+0x1ab>
mov    -0x10(%rbp),%rdi
lea    0xdac(%rip),%rsi
call   1030 <logData@plt>
lea    -0xe20(%rbp),%rdi
mov    -0xe28(%rbp),%rdx
mov    $0x3ff,%esi
call   1090 <fgets@plt>
mov    -0xe28(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0xe20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x3,%edx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
je     1324 <authenticate+0x1a4>
movl   $0x3,-0x4(%rbp)
jmp    132b <authenticate+0x1ab>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<authenticate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xe08,%rsp
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0x400(%rsp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
lea    0xe4f(%rip),%rsi
mov    %r15,%rdi
mov    $0x9,%edx
call   1080 <memcmp@plt>
test   %rax,%rax
je     12c0 <authenticate+0x140>
lea    0xe3b(%rip),%rsi
mov    %r14,%rdi
call   1030 <logData@plt>
lea    0xe56(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3ff,%esi
mov    %rbp,%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
lea    0xe41(%rip),%rdx
lea    0xe53(%rip),%rcx
lea    0x800(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x3ff,%esi
mov    %rcx,%r8
mov    %rbx,%r9
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %rbp,%rdi
call   1050 <system@plt>
mov    $0x2,%ebp
test   %eax,%eax
jne    12d6 <authenticate+0x156>
lea    0xe23(%rip),%rdx
lea    0xe13(%rip),%rcx
lea    0x400(%rsp),%rbx
mov    %rsp,%r8
mov    %rbx,%rdi
mov    $0x3ff,%esi
xor    %eax,%eax
call   1060 <snprintf@plt>
lea    0xda6(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12c7 <authenticate+0x147>
mov    %rax,%rbx
lea    0xe04(%rip),%rsi
mov    %r14,%rdi
call   1030 <logData@plt>
lea    0xa00(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x3ff,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1080 <memcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rcx,%rcx,1),%ebp
add    $0x1,%ebp
jmp    12d6 <authenticate+0x156>
mov    $0x1,%ebp
jmp    12d6 <authenticate+0x156>
lea    0xd93(%rip),%rsi
mov    %r14,%rdi
call   1030 <logData@plt>
mov    %ebp,%eax
add    $0xe08,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"baCkDoOr\00"
@.str.1 = [42 x i8] c"performing lookup for user via system()!\0A\00"
@.str.2 = [7 x i8] c"%s.txt\00"
@.str.3 = [25 x i8] c"stat %s`ls %s | grep %s`\00"
@.str.4 = [9 x i8] c"./users/\00"
@.str.5 = [5 x i8] c"%s%s\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [27 x i8] c"fopen for userfile failed\0A\00"
@.str.8 = [23 x i8] c"getting userfile info\0A\00"
define i32 @authenticate(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [512 x i8]
%9 = alloca [1024 x i8]
%10 = alloca [1024 x i8]
%11 = alloca [1024 x i8]
%12 = alloca i32*
%13 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 4)
%16 = load i8*, i8** %7
%17 = call i64 @memcmp(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 9)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %3
store i32 1, i32* %4
br label %59
20: ; preds = %3
%21 = load i32*, i32** %5
%22 = call i32 @logData(i32* %21, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%24 = load i8*, i8** %6
%25 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %23, i32 1023, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%28 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %26, i32 1023, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%30 = call i32 @system(i8* %29)
store i32 %30, i32* %13
%31 = load i32, i32* %13
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %20
store i32 2, i32* %4
br label %59
34: ; preds = %20
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%37 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %35, i32 1023, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %36)
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %39, i32** %12
%40 = load i32*, i32** %12
%41 = icmp ne i32* %40, null
br i1 %41, label %45, label %42
42: ; preds = %34
%43 = load i32*, i32** %5
%44 = call i32 @logData(i32* %43, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
store i32 2, i32* %4
br label %59
45: ; preds = %34
%46 = load i32*, i32** %5
%47 = call i32 @logData(i32* %46, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%49 = load i32*, i32** %12
%50 = call i32 @fgets(i8* %48, i32 1023, i32* %49)
%51 = load i32*, i32** %12
%52 = call i32 @fclose(i32* %51)
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%54 = load i8*, i8** %7
%55 = call i64 @memcmp(i8* %53, i8* %54, i32 3)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %45
store i32 3, i32* %4
br label %59
58: ; preds = %45
store i32 1, i32* %4
br label %59
59: ; preds = %58, %57, %42, %33, %19
%60 = load i32, i32* %4
ret i32 %60
}

LLVM IR (-O2):
@.str = [9 x i8] c"baCkDoOr\00"
@.str.1 = [42 x i8] c"performing lookup for user via system()!\0A\00"
@.str.2 = [7 x i8] c"%s.txt\00"
@.str.3 = [25 x i8] c"stat %s`ls %s | grep %s`\00"
@.str.4 = [9 x i8] c"./users/\00"
@.str.5 = [5 x i8] c"%s%s\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [27 x i8] c"fopen for userfile failed\0A\00"
@.str.8 = [23 x i8] c"getting userfile info\0A\00"
define i32 @authenticate(i32* %0, i8* %1, i8* %2) {
%4 = alloca [512 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%12 = call i32 @memset(i8* %9, i32 0, i32 4)
%13 = call i64 @memcmp(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 9)
%14 = icmp eq i64 %13, 0
br i1 %14, label %34, label %15
15: ; preds = %3
%16 = call i32 @logData(i32* %0, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %10, i32 1023, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%18 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %8, i32 1023, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%19 = call i32 @system(i8* %8)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %34
21: ; preds = %15
%22 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %9, i32 1023, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%23 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @logData(i32* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %34
27: ; preds = %21
%28 = call i32 @logData(i32* %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
%29 = call i32 @fgets(i8* %11, i32 1023, i32* %23)
%30 = call i32 @fclose(i32* %23)
%31 = call i64 @memcmp(i8* %11, i8* %2, i32 3)
%32 = icmp eq i64 %31, 0
%33 = select i1 %32, i32 1, i32 3
br label %34
34: ; preds = %27, %15, %3, %25
%35 = phi i32 [ 2, %25 ], [ 1, %3 ], [ 2, %15 ], [ %33, %27 ]
ret i32 %35
}