#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 */
struct stat {
  size_t st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(char *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, size_t, int, int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ stat(char const *, struct stat *);
char *strchr(char *, char);
char *strstr(char *, char *);
int user_del_line(const char *username, const char *filename) {
  char *buffer;
  FILE *passwd;
  size_t len;
  int begin;
  int end;
  char needle[256];
  char *start;
  char *stop;
  struct stat statbuf;
  passwd = fopen(filename, "r");
  if (!passwd)
    return -1;
  stat(filename, &statbuf);
  len = statbuf.st_size;
  buffer = (char *)malloc(len * sizeof(char));
  if (!buffer) {
    fclose(passwd);
    return -1;
  }
  fread(buffer, len, sizeof(char), passwd);
  fclose(passwd);
  snprintf(needle, 256, "\n%s:", username);
  needle[255] = 0;
  start = strstr(buffer, needle);
  if (!start) {
    begin = 0;
    end = 0;
  } else {
    start++;
    stop = strchr(start, '\n');
    begin = start - buffer;
    end = stop - buffer;
  }
  passwd = fopen(filename, "w");
  if (!passwd)
    return -1;
  fwrite(buffer, (begin - 1), sizeof(char), passwd);
  fwrite(&buffer[end], (len - end), sizeof(char), passwd);
  fclose(passwd);
  return 0;
}


x86 assembly (clang, -O0):
<user_del_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ce <user_del_line+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1357 <user_del_line+0x1c7>
mov    -0x18(%rbp),%rdi
lea    -0x158(%rbp),%rsi
call   1070 <stat@plt>
mov    -0x158(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
shl    $0x0,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121a <user_del_line+0x8a>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1357 <user_del_line+0x1c7>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x140(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    0xdb2(%rip),%rdx
call   1060 <snprintf@plt>
movb   $0x0,-0x41(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x140(%rbp),%rsi
call   10b0 <strstr@plt>
mov    %rax,-0x148(%rbp)
cmpq   $0x0,-0x148(%rbp)
jne    1291 <user_del_line+0x101>
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
jmp    12dd <user_del_line+0x14d>
mov    -0x148(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x148(%rbp)
mov    -0x148(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x150(%rbp)
mov    -0x148(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x150(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd1f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1308 <user_del_line+0x178>
movl   $0xffffffff,-0x4(%rbp)
jmp    1357 <user_del_line+0x1c7>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rsi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    -0x20(%rbp),%rdi
movslq -0x38(%rbp),%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
movslq -0x38(%rbp),%rax
sub    %rax,%rsi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<user_del_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r13
mov    %rdi,%r12
lea    0xe52(%rip),%rsi
mov    %r13,%rdi
call   1090 <fopen@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     12c5 <user_del_line+0x135>
mov    %rax,%rbp
lea    0x8(%rsp),%rsi
mov    %r13,%rdi
call   1070 <stat@plt>
mov    0x8(%rsp),%r15
mov    %r15,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     1261 <user_del_line+0xd1>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xdf6(%rip),%rdx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %r12,%rcx
call   1060 <snprintf@plt>
movb   $0x0,0x10f(%rsp)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     126b <user_del_line+0xdb>
mov    %rax,%rbp
add    $0x1,%rbp
mov    %rbp,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
sub    %ebx,%eax
mov    %ebx,%ecx
not    %ecx
add    %ecx,%ebp
movslq %ebp,%rcx
mov    %rcx,(%rsp)
movslq %eax,%r12
jmp    1276 <user_del_line+0xe6>
mov    %rbp,%rdi
call   1040 <fclose@plt>
jmp    12c5 <user_del_line+0x135>
movq   $0xffffffffffffffff,(%rsp)
ff
xor    %r12d,%r12d
lea    0xd8a(%rip),%rsi
mov    %r13,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     12c5 <user_del_line+0x135>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    (%rsp),%rsi
mov    $0x1,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
add    %r12,%rbx
sub    %r12,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %rbp,%rcx
call   10a0 <fwrite@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"\0A%s:\00"
@.str.2 = [2 x i8] c"w\00"
define i32 @user_del_line(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca [256 x i8]
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca %struct.stat
store i8* %0, i8** %4
store i8* %1, i8** %5
%15 = load i8*, i8** %5
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp ne i32* %17, null
br i1 %18, label %20, label %19
19: ; preds = %2
store i32 -1, i32* %3
br label %93
20: ; preds = %2
%21 = load i8*, i8** %5
%22 = call i32 @stat(i8* %21, %struct.stat* %14)
%23 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%24 = load i64, i64* %23
store i64 %24, i64* %8
%25 = load i64, i64* %8
%26 = mul i64 %25, 1
%27 = call i64 @malloc(i64 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = icmp ne i8* %29, null
br i1 %30, label %34, label %31
31: ; preds = %20
%32 = load i32*, i32** %7
%33 = call i32 @fclose(i32* %32)
store i32 -1, i32* %3
br label %93
34: ; preds = %20
%35 = load i8*, i8** %6
%36 = load i64, i64* %8
%37 = load i32*, i32** %7
%38 = call i32 @fread(i8* %35, i64 %36, i32 1, i32* %37)
%39 = load i32*, i32** %7
%40 = call i32 @fclose(i32* %39)
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%42 = load i8*, i8** %4
%43 = call i32 @snprintf(i8* %41, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %42)
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 255
store i8 0, i8* %44
%45 = load i8*, i8** %6
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%47 = call i8* @strstr(i8* %45, i8* %46)
store i8* %47, i8** %12
%48 = load i8*, i8** %12
%49 = icmp ne i8* %48, null
br i1 %49, label %51, label %50
50: ; preds = %34
store i32 0, i32* %9
store i32 0, i32* %10
br label %68
51: ; preds = %34
%52 = load i8*, i8** %12
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %12
%54 = load i8*, i8** %12
%55 = call i8* @strchr(i8* %54, i8 signext 10)
store i8* %55, i8** %13
%56 = load i8*, i8** %12
%57 = load i8*, i8** %6
%58 = ptrtoint i8* %56 to i64
%59 = ptrtoint i8* %57 to i64
%60 = sub i64 %58, %59
%61 = trunc i64 %60 to i32
store i32 %61, i32* %9
%62 = load i8*, i8** %13
%63 = load i8*, i8** %6
%64 = ptrtoint i8* %62 to i64
%65 = ptrtoint i8* %63 to i64
%66 = sub i64 %64, %65
%67 = trunc i64 %66 to i32
store i32 %67, i32* %10
br label %68
68: ; preds = %51, %50
%69 = load i8*, i8** %5
%70 = call i32* @fopen(i8* %69, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %70, i32** %7
%71 = load i32*, i32** %7
%72 = icmp ne i32* %71, null
br i1 %72, label %74, label %73
73: ; preds = %68
store i32 -1, i32* %3
br label %93
74: ; preds = %68
%75 = load i8*, i8** %6
%76 = load i32, i32* %9
%77 = sub nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = load i32*, i32** %7
%80 = call i32 @fwrite(i8* %75, i64 %78, i32 1, i32* %79)
%81 = load i8*, i8** %6
%82 = load i32, i32* %10
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %81, i64 %83
%85 = load i64, i64* %8
%86 = load i32, i32* %10
%87 = sext i32 %86 to i64
%88 = sub i64 %85, %87
%89 = load i32*, i32** %7
%90 = call i32 @fwrite(i8* %84, i64 %88, i32 1, i32* %89)
%91 = load i32*, i32** %7
%92 = call i32 @fclose(i32* %91)
store i32 0, i32* %3
br label %93
93: ; preds = %74, %73, %31, %19
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"\0A%s:\00"
@.str.2 = [2 x i8] c"w\00"
define i32 @user_del_line(i8* %0, i8* nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %48, label %9
9: ; preds = %2
%10 = call i32 @stat(i8* %1, %struct.stat* %4)
%11 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%12 = load i64, i64* %11
%13 = tail call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
%15 = icmp eq i64 %13, 0
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = tail call i32 @fclose(i32* %7)
br label %48
18: ; preds = %9
%19 = tail call i32 @fread(i8* %14, i64 %12, i32 1, i32* %7)
%20 = tail call i32 @fclose(i32* %7)
%21 = call i32 @snprintf(i8* %5, i32 256, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 255
store i8 0, i8* %22
%23 = call i8* @strstr(i8* %14, i8* %5)
%24 = icmp eq i8* %23, null
br i1 %24, label %37, label %25
25: ; preds = %18
%26 = getelementptr inbounds i8, i8* %23, i64 1
%27 = call i8* @strchr(i8* %26, i8 signext 10)
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %29, %13
%31 = xor i64 %13, -1
%32 = add i64 %28, %31
%33 = shl i64 %32, 32
%34 = ashr exact i64 %33, 32
%35 = shl i64 %30, 32
%36 = ashr exact i64 %35, 32
br label %37
37: ; preds = %18, %25
%38 = phi i64 [ %34, %25 ], [ -1, %18 ]
%39 = phi i64 [ %36, %25 ], [ 0, %18 ]
%40 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp eq i32* %40, null
br i1 %41, label %48, label %42
42: ; preds = %37
%43 = call i32 @fwrite(i8* %14, i64 %38, i32 1, i32* %40)
%44 = getelementptr inbounds i8, i8* %14, i64 %39
%45 = sub i64 %12, %39
%46 = call i32 @fwrite(i8* %44, i64 %45, i32 1, i32* %40)
%47 = call i32 @fclose(i32* %40)
br label %48
48: ; preds = %37, %2, %42, %16
%49 = phi i32 [ 0, %42 ], [ -1, %16 ], [ -1, %2 ], [ -1, %37 ]
ret i32 %49
}