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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int update_record(char status, char *file, char *name) {
  int result = 0;
  long int pos;
  char line[1024];
  FILE *fp = fopen(file, "r+");
  if (fp == NULL) {
    return -1;
  }
  fgets(line, 1024, fp);
  pos = ftell(fp);
  while (fgets(line, 1024, fp)) {
    line[strlen(line) - 1] = 0;
    if (strcmp(line + 1, name) == 0) {
      fseek(fp, pos, SEEK_SET);
      fprintf(fp, "%c%s", status, name);
      result = 1;
      break;
    }
    pos = ftell(fp);
  }
  fclose(fp);
  return result;
}


x86 assembly (clang, -O0):
<update_record>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x438(%rbp)
jne    11d1 <update_record+0x51>
movl   $0xffffffff,-0x4(%rbp)
jmp    12bb <update_record+0x13b>
lea    -0x430(%rbp),%rdi
mov    -0x438(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
mov    -0x438(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x28(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x438(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12a9 <update_record+0x129>
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x430(%rbp,%rax,1)
lea    -0x430(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1294 <update_record+0x114>
mov    -0x438(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2d7c(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
mov    -0x438(%rbp),%rdi
mov    -0x5(%rbp),%al
mov    -0x18(%rbp),%rcx
lea    0xd83(%rip),%rsi
movsbl %al,%edx
call   1070 <fprintf@plt>
movl   $0x1,-0x1c(%rbp)
jmp    12a9 <update_record+0x129>
mov    -0x438(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x28(%rbp)
jmp    11f9 <update_record+0x79>
mov    -0x438(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_record>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdx,%r14
mov    %rsi,%rax
mov    %edi,%r15d
lea    0xe5f(%rip),%rsi
mov    %rax,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1242 <update_record+0xc2>
mov    %rax,%rbx
lea    0x10(%rsp),%r13
mov    %r13,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %rax,%rbp
mov    %r13,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     127f <update_record+0xff>
mov    %r15d,0xc(%rsp)
lea    0x11(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r13,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     124a <update_record+0xca>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %rax,%rbp
mov    %r13,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1200 <update_record+0x80>
jmp    127f <update_record+0xff>
mov    $0xffffffff,%r12d
jmp    1287 <update_record+0x107>
mov    0xc(%rsp),%r15d
mov    0x2d8a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <fseek@plt>
movsbl %r15b,%edx
lea    0xd95(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rcx
call   1070 <fprintf@plt>
mov    $0x1,%r12d
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r12d,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"r+\00"
@SEEK_SET = global i32 0
@.str.1 = [5 x i8] c"%c%s\00"
define i32 @update_record(i8 signext %0, i8* nocapture %1, i8* %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* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %40, label %8
8: ; preds = %3
%9 = call i64 @fgets(i8* %5, i32 1024, i32* %6)
%10 = call i64 @ftell(i32* %6)
%11 = call i64 @fgets(i8* %5, i32 1024, i32* %6)
%12 = icmp eq i64 %11, 0
br i1 %12, label %37, label %13
13: ; preds = %8
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1
%15 = call i32 @strlen(i8* %5)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i64 @strcmp(i8* %14, i8* %2)
%20 = icmp eq i64 %19, 0
br i1 %20, label %28, label %33
21: ; preds = %33
%22 = call i32 @strlen(i8* %5)
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i64 @strcmp(i8* %14, i8* %2)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %21, %13
%29 = phi i64 [ %10, %13 ], [ %34, %21 ]
%30 = load i32, i32* @SEEK_SET
%31 = call i32 @fseek(i32* %6, i64 %29, i32 %30)
%32 = call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 signext %0, i8* %2)
br label %37
33: ; preds = %13, %21
%34 = call i64 @ftell(i32* %6)
%35 = call i64 @fgets(i8* %5, i32 1024, i32* %6)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %21
37: ; preds = %33, %8, %28
%38 = phi i32 [ 1, %28 ], [ 0, %8 ], [ 0, %33 ]
%39 = call i32 @fclose(i32* %6)
br label %40
40: ; preds = %3, %37
%41 = phi i32 [ %38, %37 ], [ -1, %3 ]
ret i32 %41
}