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

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ REG_ICASE;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char tolower(char);
char *retlinelogin(char *item) {
  FILE *fp;
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  regex_t regex;
  int reti;
  int i;
  for (i = 0; item[i]; i++) {
    item[i] = tolower(item[i]);
  }
  reti = regcomp(&regex, item, REG_ICASE);
  if (reti) {
    fprintf(stderr, "Could not compile regex\n");
    exit(1);
  }
  fp = fopen("/etc/passwd", "r");
  if (fp == NULL)
    exit(EXIT_FAILURE);
  while ((read = getline(&line, &len, fp)) != -1) {
    int i = 0;
    char auxline[20];
    bzero(auxline, 20);
    while (line[i] != ':') {
      auxline[i] = line[i];
      i++;
    }
    if (strcmp(item, auxline) == 0) {
      return line;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<retlinelogin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11e1 <retlinelogin+0x61>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <tolower@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11a3 <retlinelogin+0x23>
mov    -0x10(%rbp),%rsi
mov    0x2dfc(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rdi
call   1030 <regcomp@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1223 <retlinelogin+0xa3>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdef(%rip),%rdi
lea    0xdf4(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1253 <retlinelogin+0xd3>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1258 <retlinelogin+0xd8>
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     12e9 <retlinelogin+0x169>
movl   $0x0,-0x3c(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x14,%esi
call   1080 <bzero@plt>
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
je     12c0 <retlinelogin+0x140>
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x3c(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    128a <retlinelogin+0x10a>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    12e4 <retlinelogin+0x164>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12f1 <retlinelogin+0x171>
jmp    1258 <retlinelogin+0xd8>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<retlinelogin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%r15
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    (%rdi),%al
test   %al,%al
je     11c6 <retlinelogin+0x46>
lea    0x1(%r15),%rbx
nopl   (%rax)
movsbl %al,%edi
call   1060 <tolower@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11b0 <retlinelogin+0x30>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edx
lea    0x1c(%rsp),%rdi
mov    %r15,%rsi
call   1030 <regcomp@plt>
test   %eax,%eax
jne    128b <retlinelogin+0x10b>
lea    0xe2e(%rip),%rdi
lea    0xe33(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12aa <retlinelogin+0x12a>
mov    %rax,%rbx
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%r13
xor    %r14d,%r14d
lea    0x20(%rsp),%rbp
jmp    1230 <retlinelogin+0xb0>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1274 <retlinelogin+0xf4>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     1279 <retlinelogin+0xf9>
mov    %rbp,%rdi
mov    $0x14,%esi
call   1080 <bzero@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%cl
cmp    $0x3a,%cl
je     1220 <retlinelogin+0xa0>
xor    %edx,%edx
xchg   %ax,%ax
mov    %cl,0x20(%rsp,%rdx,1)
movzbl 0x1(%rax,%rdx,1),%ecx
add    $0x1,%rdx
cmp    $0x3a,%cl
jne    1260 <retlinelogin+0xe0>
jmp    1220 <retlinelogin+0xa0>
mov    0x8(%rsp),%r14
mov    %r14,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
lea    0xd65(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@REG_ICASE = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"Could not compile regex\0A\00"
@.str.1 = [12 x i8] c"/etc/passwd\00"
@.str.2 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
define i8* @retlinelogin(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [20 x i8]
store i8* %0, i8** %3
store i8* null, i8** %5
store i64 0, i64* %6
store i32 0, i32* %10
br label %13
13: ; preds = %31, %1
%14 = load i8*, i8** %3
%15 = load i32, i32* %10
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %34
20: ; preds = %13
%21 = load i8*, i8** %3
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = call signext i8 @tolower(i8 signext %25)
%27 = load i8*, i8** %3
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 %26, i8* %30
br label %31
31: ; preds = %20
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
store i32 %33, i32* %10
br label %13
34: ; preds = %13
%35 = load i8*, i8** %3
%36 = load i32, i32* @REG_ICASE
%37 = call i32 @regcomp(i32* %8, i8* %35, i32 %36)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %34
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %34
%45 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %45, i32** %4
%46 = load i32*, i32** %4
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %44
br label %52
52: ; preds = %85, %51
%53 = load i32*, i32** %4
%54 = call i32 @getline(i8** %5, i64* %6, i32* %53)
store i32 %54, i32* %7
%55 = icmp ne i32 %54, -1
br i1 %55, label %56, label %86
56: ; preds = %52
store i32 0, i32* %11
%57 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%58 = call i32 @bzero(i8* %57, i32 20)
br label %59
59: ; preds = %67, %56
%60 = load i8*, i8** %5
%61 = load i32, i32* %11
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp ne i32 %65, 58
br i1 %66, label %67, label %78
67: ; preds = %59
%68 = load i8*, i8** %5
%69 = load i32, i32* %11
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = load i8, i8* %71
%73 = load i32, i32* %11
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 %74
store i8 %72, i8* %75
%76 = load i32, i32* %11
%77 = add nsw i32 %76, 1
store i32 %77, i32* %11
br label %59
78: ; preds = %59
%79 = load i8*, i8** %3
%80 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%81 = call i64 @strcmp(i8* %79, i8* %80)
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %78
%84 = load i8*, i8** %5
store i8* %84, i8** %2
br label %87
85: ; preds = %78
br label %52
86: ; preds = %52
store i8* null, i8** %2
br label %87
87: ; preds = %86, %83
%88 = load i8*, i8** %2
ret i8* %88
}

LLVM IR (-O2):
@REG_ICASE = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"Could not compile regex\0A\00"
@.str.1 = [12 x i8] c"/etc/passwd\00"
@.str.2 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
define i8* @retlinelogin(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca [20 x i8]
%6 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%7 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%8 = bitcast i32* %4 to i8*
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %1, %11
%12 = phi i64 [ %16, %11 ], [ 0, %1 ]
%13 = phi i8 [ %18, %11 ], [ %9, %1 ]
%14 = phi i8* [ %17, %11 ], [ %0, %1 ]
%15 = tail call signext i8 @tolower(i8 signext %13)
store i8 %15, i8* %14
%16 = add nuw i64 %12, 1
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %11
20: ; preds = %11, %1
%21 = load i32, i32* @REG_ICASE
%22 = call i32 @regcomp(i32* %4, i8* %0, i32 %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
br label %36
33: ; preds = %28
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %31, %52
%37 = call i32 @getline(i8** %2, i64* %3, i32* %29)
%38 = icmp eq i32 %37, -1
br i1 %38, label %56, label %39
39: ; preds = %36
%40 = call i32 @bzero(i8* %32, i32 20)
%41 = load i8*, i8** %2
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 58
br i1 %43, label %52, label %44
44: ; preds = %39, %44
%45 = phi i64 [ %48, %44 ], [ 0, %39 ]
%46 = phi i8 [ %50, %44 ], [ %42, %39 ]
%47 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %45
store i8 %46, i8* %47
%48 = add nuw nsw i64 %45, 1
%49 = getelementptr inbounds i8, i8* %41, i64 %48
%50 = load i8, i8* %49
%51 = icmp eq i8 %50, 58
br i1 %51, label %52, label %44
52: ; preds = %44, %39
%53 = call i64 @strcmp(i8* %0, i8* %32)
%54 = icmp eq i64 %53, 0
%55 = load i8*, i8** %2
br i1 %54, label %56, label %36
56: ; preds = %36, %52
%57 = phi i8* [ %55, %52 ], [ null, %36 ]
ret i8* %57
}