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

/* Variables and functions */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
char *realpath(char *, char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int Delete_in_File(char *filename, int delete_line) {
  char file_path[512], copy_file[1024];
  char *ptr;
  ptr = realpath(filename, file_path);
  snprintf(copy_file, sizeof(copy_file), "%s_copy", ptr);
  FILE *fileptr1, *fileptr2;
  char ch;
  int temp = 1;
  fileptr1 = fopen(filename, "r");
  ch = fgetc(fileptr1);
  fileptr2 = fopen(copy_file, "w");
  while (ch != EOF) {
    if (ch == '\n')
      temp++;
    if (temp != delete_line) {
      fputc(ch, fileptr2);
    }
    ch = fgetc(fileptr1);
  }
  fclose(fileptr1);
  fclose(fileptr2);
  remove(filename);
  rename(copy_file, filename);
  return 0;
}


x86 assembly (clang, -O0):
<Delete_in_File>:
push   %rbp
mov    %rsp,%rbp
sub    $0x630,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1080 <realpath@plt>
mov    %rax,-0x618(%rbp)
lea    -0x610(%rbp),%rdi
mov    -0x618(%rbp),%rcx
mov    $0x400,%esi
lea    0xe3d(%rip),%rdx
call   1050 <snprintf@plt>
movl   $0x1,-0x630(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x620(%rbp)
mov    -0x620(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x629(%rbp)
lea    -0x610(%rbp),%rdi
lea    0xe01(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x628(%rbp)
movsbl -0x629(%rbp),%eax
mov    0x2dc5(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1288 <Delete_in_File+0x108>
movsbl -0x629(%rbp),%eax
cmp    $0xa,%eax
jne    124d <Delete_in_File+0xcd>
mov    -0x630(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x630(%rbp)
mov    -0x630(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1271 <Delete_in_File+0xf1>
mov    -0x629(%rbp),%al
mov    -0x628(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
mov    -0x620(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x629(%rbp)
jmp    1215 <Delete_in_File+0x95>
mov    -0x620(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x628(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%rdi
call   1030 <remove@plt>
lea    -0x610(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10a0 <rename@plt>
xor    %eax,%eax
add    $0x630,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Delete_in_File>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x618,%rsp
mov    %esi,%r12d
mov    %rdi,%rbx
lea    0x410(%rsp),%rsi
call   1080 <realpath@plt>
lea    0xe55(%rip),%rdx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rax,%rcx
call   1050 <snprintf@plt>
lea    0xe41(%rip),%rsi
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebx
lea    0xe22(%rip),%rsi
mov    %r15,%rdi
call   1090 <fopen@plt>
mov    %rax,%r15
mov    0x2dee(%rip),%r13
cmp    0x0(%r13),%bl
jne    123e <Delete_in_File+0xbe>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <remove@plt>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   10a0 <rename@plt>
xor    %eax,%eax
add    $0x618,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r14d
jmp    1260 <Delete_in_File+0xe0>
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebx
cmp    0x0(%r13),%al
je     1200 <Delete_in_File+0x80>
mov    %r14d,%eax
xor    %r14d,%r14d
cmp    $0xa,%bl
sete   %r14b
add    %eax,%r14d
cmp    %r12d,%r14d
je     1250 <Delete_in_File+0xd0>
movsbl %bl,%edi
mov    %r15,%rsi
call   1070 <fputc@plt>
jmp    1250 <Delete_in_File+0xd0>

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

LLVM IR (-O2):
@.str = [8 x i8] c"%s_copy\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@EOF = global i8 0
define i32 @Delete_in_File(i8* nocapture %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i8* @realpath(i8* %0, i8* %5)
%8 = call i32 @snprintf(i8* %6, i32 1024, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = call signext i8 @fgetc(i32* %9)
%11 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = load i8, i8* @EOF
%13 = icmp eq i8 %10, %12
br i1 %13, label %27, label %14
14: ; preds = %2, %23
%15 = phi i32 [ %19, %23 ], [ 1, %2 ]
%16 = phi i8 [ %24, %23 ], [ %10, %2 ]
%17 = icmp eq i8 %16, 10
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %15, %18
%20 = icmp eq i32 %19, %1
br i1 %20, label %23, label %21
21: ; preds = %14
%22 = call i32 @fputc(i8 signext %16, i32* %11)
br label %23
23: ; preds = %21, %14
%24 = call signext i8 @fgetc(i32* %9)
%25 = load i8, i8* @EOF
%26 = icmp eq i8 %24, %25
br i1 %26, label %27, label %14
27: ; preds = %23, %2
%28 = call i32 @fclose(i32* %9)
%29 = call i32 @fclose(i32* %11)
%30 = call i32 @remove(i8* %0)
%31 = call i32 @rename(i8* %6, i8* %0)
ret i32 0
}