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

/* Variables and functions */
int /*<<< orphan*/ cleanline(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *malloc(scalar_t__);
char *strchr(char *, char);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *getpw(char *file, char *user, char **pass) {
  char buf[1024];
  FILE *infile = fopen(file, "r");
  if (!infile)
    return (NULL);
  while (fgets(buf, sizeof(buf), infile)) {
    cleanline(buf, 1 | 2 | 4);
    char *tmp = strchr(buf, ':');
    if (!tmp)
      continue;
    *tmp++ = '\0';
    if (!strcmp(buf, user)) {
      *pass = malloc(strlen(tmp) + 1);
      strcpy(*pass, tmp);
      fclose(infile);
      return (*pass);
    }
  }
  fclose(infile);
  return (NULL);
}


x86 assembly (clang, -O0):
<getpw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    11d9 <getpw+0x49>
movq   $0x0,-0x8(%rbp)
jmp    12d7 <getpw+0x147>
jmp    11de <getpw+0x4e>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12c3 <getpw+0x133>
lea    -0x420(%rbp),%rdi
mov    $0x7,%esi
call   10a0 <cleanline@plt>
lea    -0x420(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
jne    123c <getpw+0xac>
jmp    11de <getpw+0x4e>
mov    -0x430(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x430(%rbp)
movb   $0x0,(%rax)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    12be <getpw+0x12e>
mov    -0x430(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x430(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x428(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    12d7 <getpw+0x147>
jmp    11de <getpw+0x4e>
mov    -0x428(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpw>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xe53(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1261 <getpw+0xd1>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1259 <getpw+0xc9>
mov    %rsp,%r13
jmp    11f5 <getpw+0x65>
nopl   0x0(%rax)
mov    %r13,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1259 <getpw+0xc9>
mov    %r13,%rdi
mov    $0x7,%esi
call   10a0 <cleanline@plt>
mov    %r13,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11e0 <getpw+0x50>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %r13,%rdi
mov    %r15,%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
jne    11e0 <getpw+0x50>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1090 <malloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    (%r14),%rax
jmp    1263 <getpw+0xd3>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i8* @getpw(i8* %0, i8* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca [1024 x i8]
%9 = alloca i32*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %9
%13 = load i32*, i32** %9
%14 = icmp ne i32* %13, null
br i1 %14, label %16, label %15
15: ; preds = %3
store i8* null, i8** %4
br label %55
16: ; preds = %3
br label %17
17: ; preds = %51, %29, %16
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%19 = load i32*, i32** %9
%20 = call i64 @fgets(i8* %18, i32 1024, i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %52
22: ; preds = %17
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%24 = call i32 @cleanline(i8* %23, i32 7)
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%26 = call i8* @strchr(i8* %25, i8 signext 58)
store i8* %26, i8** %10
%27 = load i8*, i8** %10
%28 = icmp ne i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %22
br label %17
30: ; preds = %22
%31 = load i8*, i8** %10
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %10
store i8 0, i8* %31
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%34 = load i8*, i8** %6
%35 = call i32 @strcmp(i8* %33, i8* %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %51, label %37
37: ; preds = %30
%38 = load i8*, i8** %10
%39 = call i64 @strlen(i8* %38)
%40 = add nsw i64 %39, 1
%41 = call i8* @malloc(i64 %40)
%42 = load i8**, i8*** %7
store i8* %41, i8** %42
%43 = load i8**, i8*** %7
%44 = load i8*, i8** %43
%45 = load i8*, i8** %10
%46 = call i32 @strcpy(i8* %44, i8* %45)
%47 = load i32*, i32** %9
%48 = call i32 @fclose(i32* %47)
%49 = load i8**, i8*** %7
%50 = load i8*, i8** %49
store i8* %50, i8** %4
br label %55
51: ; preds = %30
br label %17
52: ; preds = %17
%53 = load i32*, i32** %9
%54 = call i32 @fclose(i32* %53)
store i8* null, i8** %4
br label %55
55: ; preds = %52, %37, %15
%56 = load i8*, i8** %4
ret i8* %56
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i8* @getpw(i8* nocapture %0, i8* nocapture %1, i8** nocapture %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %31, label %8
8: ; preds = %3
%9 = call i64 @fgets(i8* %5, i32 1024, i32* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %29, label %11
11: ; preds = %8, %26
%12 = call i32 @cleanline(i8* %5, i32 7)
%13 = call i8* @strchr(i8* %5, i8 signext 58)
%14 = icmp eq i8* %13, null
br i1 %14, label %26, label %15
15: ; preds = %11
store i8 0, i8* %13
%16 = call i32 @strcmp(i8* %5, i8* dereferenceable(1) %1)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = getelementptr inbounds i8, i8* %13, i64 1
%20 = call i64 @strlen(i8* %19)
%21 = add nsw i64 %20, 1
%22 = call i8* @malloc(i64 %21)
store i8* %22, i8** %2
%23 = call i32 @strcpy(i8* %22, i8* %19)
%24 = call i32 @fclose(i32* %6)
%25 = load i8*, i8** %2
br label %31
26: ; preds = %15, %11
%27 = call i64 @fgets(i8* %5, i32 1024, i32* %6)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %11
29: ; preds = %26, %8
%30 = call i32 @fclose(i32* %6)
br label %31
31: ; preds = %18, %3, %29
%32 = phi i8* [ null, %29 ], [ null, %3 ], [ %25, %18 ]
ret i8* %32
}