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

/* Variables and functions */
scalar_t__ chmod(char const *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
char *malloc(size_t);
int mkstemp(char *);
scalar_t__ rename(char *, char const *);
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char *, size_t);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char const *, char);
int write(int, char *, int);
int deleteAccountId(const char *pUsername, const char *pAccounts) {
  char *line = NULL;
  size_t len = 0;
  size_t pathlen = 0;
  ssize_t read;
  FILE *fp;
  int fp_dest;
  char *nameBuff;
  fp = fopen(pAccounts, "r");
  if (fp == NULL) {
    return -1;
  }
  char *pLastSlash = strrchr(pAccounts, '/');
  if (pLastSlash != NULL)
    pathlen = pLastSlash - pAccounts + 1;
  nameBuff = malloc(pathlen + 12 + 1);
  strncpy(nameBuff, pAccounts, pathlen);
  strncpy(nameBuff + pathlen, "latch-XXXXXX", 12);
  nameBuff[pathlen + 12] = '\0';
  fp_dest = mkstemp(nameBuff);
  if (fp_dest == -1) {
    fclose(fp);
    return -1;
  }
  while ((read = getline(&line, &len, fp)) != -1) {
    if (!(strncmp(pUsername, line, strlen(pUsername)) == 0 &&
          line[strlen(pUsername)] == ':')) {
      if (write(fp_dest, line, read) != read) {
        free(line);
        close(fp_dest);
        fclose(fp);
        return -1;
      }
    }
  }
  free(line);
  close(fp_dest);
  fclose(fp);
  if (rename(nameBuff, pAccounts) != 0) {
    return 1;
  }
  if (chmod(pAccounts, 0600) < 0) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<deleteAccountId>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xded(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1233 <deleteAccountId+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    1406 <deleteAccountId+0x226>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1263 <deleteAccountId+0x83>
mov    -0x58(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
add    $0xc,%rdi
add    $0x1,%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x50(%rbp),%rdi
add    -0x30(%rbp),%rdi
lea    0xd68(%rip),%rsi
mov    $0xc,%edx
call   1040 <strncpy@plt>
mov    -0x50(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,0xc(%rax,%rcx,1)
mov    -0x50(%rbp),%rdi
call   10c0 <mkstemp@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    12dc <deleteAccountId+0xfc>
mov    -0x40(%rbp),%rdi
call   1070 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1406 <deleteAccountId+0x226>
jmp    12e1 <deleteAccountId+0x101>
mov    -0x40(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1100 <getline@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     139e <deleteAccountId+0x1be>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    %rax,%rdx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    1356 <deleteAccountId+0x176>
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <strlen@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
je     1399 <deleteAccountId+0x1b9>
mov    -0x44(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1060 <write@plt>
cmp    -0x34(%rbp),%eax
je     1394 <deleteAccountId+0x1b4>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%edi
call   10a0 <close@plt>
mov    -0x40(%rbp),%rdi
call   1070 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1406 <deleteAccountId+0x226>
jmp    1399 <deleteAccountId+0x1b9>
jmp    12e1 <deleteAccountId+0x101>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%edi
call   10a0 <close@plt>
mov    -0x40(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10f0 <rename@plt>
cmp    $0x0,%rax
je     13db <deleteAccountId+0x1fb>
movl   $0x1,-0x4(%rbp)
jmp    1406 <deleteAccountId+0x226>
mov    -0x18(%rbp),%rdi
mov    $0x180,%esi
call   10d0 <chmod@plt>
cmp    $0x0,%rax
jge    13ff <deleteAccountId+0x21f>
movl   $0x1,-0x4(%rbp)
jmp    1406 <deleteAccountId+0x226>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deleteAccountId>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
movq   $0x0,(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xdf4(%rip),%rsi
mov    %r14,%rdi
call   10e0 <fopen@plt>
mov    $0xffffffff,%r13d
test   %rax,%rax
je     139a <deleteAccountId+0x1ba>
mov    %rax,0x8(%rsp)
mov    %r14,%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
mov    %rax,%rbp
sub    %r14,%rbp
add    $0x1,%rbp
test   %rax,%rax
cmove  %rax,%rbp
lea    0xd(%rbp),%rdi
call   10b0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <strncpy@plt>
lea    (%rbx,%rbp,1),%rdi
lea    0xd98(%rip),%rsi
mov    $0xc,%edx
call   1040 <strncpy@plt>
movb   $0x0,0xc(%rbx,%rbp,1)
mov    %rbx,0x20(%rsp)
mov    %rbx,%rdi
call   10c0 <mkstemp@plt>
cmp    $0xffffffff,%eax
je     136f <deleteAccountId+0x18f>
mov    %eax,%r15d
mov    %r14,0x18(%rsp)
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
mov    0x8(%rsp),%rbx
mov    %rbx,%rdx
call   1100 <getline@plt>
cmp    $0xffffffff,%eax
je     1323 <deleteAccountId+0x143>
mov    %eax,%r13d
jmp    12ef <deleteAccountId+0x10f>
cs nopw 0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %r14,%rsi
mov    %r13d,%edx
call   1060 <write@plt>
cmp    %r13d,%eax
jne    137b <deleteAccountId+0x19b>
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   1100 <getline@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
je     1323 <deleteAccountId+0x143>
mov    (%rsp),%rbp
mov    %r12,%rdi
call   1080 <strlen@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1050 <strncmp@plt>
mov    (%rsp),%r14
test   %rax,%rax
jne    12c0 <deleteAccountId+0xe0>
mov    %r12,%rdi
call   1080 <strlen@plt>
cmpb   $0x3a,(%r14,%rax,1)
jne    12c0 <deleteAccountId+0xe0>
jmp    12d7 <deleteAccountId+0xf7>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    0x20(%rsp),%rdi
mov    0x18(%rsp),%rbx
mov    %rbx,%rsi
call   10f0 <rename@plt>
mov    $0x1,%r13d
test   %rax,%rax
jne    139a <deleteAccountId+0x1ba>
mov    %rbx,%rdi
mov    $0x180,%esi
call   10d0 <chmod@plt>
mov    %rax,%r13
shr    $0x3f,%r13
jmp    139a <deleteAccountId+0x1ba>
mov    0x8(%rsp),%rdi
call   1070 <fclose@plt>
jmp    139a <deleteAccountId+0x1ba>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [13 x i8] c"latch-XXXXXX\00"
define i32 @deleteAccountId(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
store i64 0, i64* %7
store i64 0, i64* %8
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %10
%16 = load i32*, i32** %10
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 -1, i32* %3
br label %110
19: ; preds = %2
%20 = load i8*, i8** %5
%21 = call i8* @strrchr(i8* %20, i8 signext 47)
store i8* %21, i8** %13
%22 = load i8*, i8** %13
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %31
24: ; preds = %19
%25 = load i8*, i8** %13
%26 = load i8*, i8** %5
%27 = ptrtoint i8* %25 to i64
%28 = ptrtoint i8* %26 to i64
%29 = sub i64 %27, %28
%30 = add nsw i64 %29, 1
store i64 %30, i64* %8
br label %31
31: ; preds = %24, %19
%32 = load i64, i64* %8
%33 = add i64 %32, 12
%34 = add i64 %33, 1
%35 = call i8* @malloc(i64 %34)
store i8* %35, i8** %12
%36 = load i8*, i8** %12
%37 = load i8*, i8** %5
%38 = load i64, i64* %8
%39 = trunc i64 %38 to i32
%40 = call i32 @strncpy(i8* %36, i8* %37, i32 %39)
%41 = load i8*, i8** %12
%42 = load i64, i64* %8
%43 = getelementptr inbounds i8, i8* %41, i64 %42
%44 = call i32 @strncpy(i8* %43, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%45 = load i8*, i8** %12
%46 = load i64, i64* %8
%47 = add i64 %46, 12
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 0, i8* %48
%49 = load i8*, i8** %12
%50 = call i32 @mkstemp(i8* %49)
store i32 %50, i32* %11
%51 = load i32, i32* %11
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %56
53: ; preds = %31
%54 = load i32*, i32** %10
%55 = call i32 @fclose(i32* %54)
store i32 -1, i32* %3
br label %110
56: ; preds = %31
br label %57
57: ; preds = %91, %56
%58 = load i32*, i32** %10
%59 = call i32 @getline(i8** %6, i64* %7, i32* %58)
store i32 %59, i32* %9
%60 = icmp ne i32 %59, -1
br i1 %60, label %61, label %92
61: ; preds = %57
%62 = load i8*, i8** %4
%63 = load i8*, i8** %6
%64 = load i8*, i8** %4
%65 = call i64 @strlen(i8* %64)
%66 = call i64 @strncmp(i8* %62, i8* %63, i64 %65)
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %76
68: ; preds = %61
%69 = load i8*, i8** %6
%70 = load i8*, i8** %4
%71 = call i64 @strlen(i8* %70)
%72 = getelementptr inbounds i8, i8* %69, i64 %71
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %74, 58
br i1 %75, label %91, label %76
76: ; preds = %68, %61
%77 = load i32, i32* %11
%78 = load i8*, i8** %6
%79 = load i32, i32* %9
%80 = call i32 @write(i32 %77, i8* %78, i32 %79)
%81 = load i32, i32* %9
%82 = icmp ne i32 %80, %81
br i1 %82, label %83, label %90
83: ; preds = %76
%84 = load i8*, i8** %6
%85 = call i32 @free(i8* %84)
%86 = load i32, i32* %11
%87 = call i32 @close(i32 %86)
%88 = load i32*, i32** %10
%89 = call i32 @fclose(i32* %88)
store i32 -1, i32* %3
br label %110
90: ; preds = %76
br label %91
91: ; preds = %90, %68
br label %57
92: ; preds = %57
%93 = load i8*, i8** %6
%94 = call i32 @free(i8* %93)
%95 = load i32, i32* %11
%96 = call i32 @close(i32 %95)
%97 = load i32*, i32** %10
%98 = call i32 @fclose(i32* %97)
%99 = load i8*, i8** %12
%100 = load i8*, i8** %5
%101 = call i64 @rename(i8* %99, i8* %100)
%102 = icmp ne i64 %101, 0
br i1 %102, label %103, label %104
103: ; preds = %92
store i32 1, i32* %3
br label %110
104: ; preds = %92
%105 = load i8*, i8** %5
%106 = call i64 @chmod(i8* %105, i32 384)
%107 = icmp slt i64 %106, 0
br i1 %107, label %108, label %109
108: ; preds = %104
store i32 1, i32* %3
br label %110
109: ; preds = %104
store i32 0, i32* %3
br label %110
110: ; preds = %109, %108, %103, %83, %53, %18
%111 = load i32, i32* %3
ret i32 %111
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [13 x i8] c"latch-XXXXXX\00"
define i32 @deleteAccountId(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%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 %66, label %9
9: ; preds = %2
%10 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 47)
%11 = icmp eq i8* %10, null
%12 = ptrtoint i8* %10 to i64
%13 = ptrtoint i8* %1 to i64
%14 = sub i64 1, %13
%15 = add i64 %14, %12
%16 = select i1 %11, i64 0, i64 %15
%17 = add i64 %16, 12
%18 = add i64 %16, 13
%19 = tail call i8* @malloc(i64 %18)
%20 = trunc i64 %16 to i32
%21 = tail call i32 @strncpy(i8* %19, i8* %1, i32 %20)
%22 = getelementptr inbounds i8, i8* %19, i64 %16
%23 = tail call i32 @strncpy(i8* %22, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%24 = getelementptr inbounds i8, i8* %19, i64 %17
store i8 0, i8* %24
%25 = tail call i32 @mkstemp(i8* %19)
%26 = icmp eq i32 %25, -1
br i1 %26, label %30, label %27
27: ; preds = %9
%28 = call i32 @getline(i8** %3, i64* %4, i32* %7)
%29 = icmp eq i32 %28, -1
br i1 %29, label %55, label %32
30: ; preds = %9
%31 = tail call i32 @fclose(i32* %7)
br label %66
32: ; preds = %27, %52
%33 = phi i32 [ %53, %52 ], [ %28, %27 ]
%34 = load i8*, i8** %3
%35 = call i64 @strlen(i8* dereferenceable(1) %0)
%36 = call i64 @strncmp(i8* %0, i8* %34, i64 %35)
%37 = icmp eq i64 %36, 0
%38 = load i8*, i8** %3
br i1 %37, label %39, label %44
39: ; preds = %32
%40 = call i64 @strlen(i8* dereferenceable(1) %0)
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 58
br i1 %43, label %52, label %44
44: ; preds = %32, %39
%45 = call i32 @write(i32 %25, i8* %38, i32 %33)
%46 = icmp eq i32 %45, %33
br i1 %46, label %52, label %47
47: ; preds = %44
%48 = load i8*, i8** %3
%49 = call i32 @free(i8* %48)
%50 = call i32 @close(i32 %25)
%51 = call i32 @fclose(i32* %7)
br label %66
52: ; preds = %44, %39
%53 = call i32 @getline(i8** %3, i64* %4, i32* %7)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %32
55: ; preds = %52, %27
%56 = load i8*, i8** %3
%57 = call i32 @free(i8* %56)
%58 = call i32 @close(i32 %25)
%59 = call i32 @fclose(i32* %7)
%60 = call i64 @rename(i8* %19, i8* %1)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %55
%63 = call i64 @chmod(i8* %1, i32 384)
%64 = lshr i64 %63, 63
%65 = trunc i64 %64 to i32
br label %66
66: ; preds = %30, %47, %55, %62, %2
%67 = phi i32 [ -1, %2 ], [ -1, %30 ], [ -1, %47 ], [ 1, %55 ], [ %65, %62 ]
ret i32 %67
}