#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*/ dprintf(int, char *, char *, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ remove(char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
char *strrchr(char *, char);
int usage(char *);
int main(int argc, char **argv) {
  if (argc != 2)
    return usage(argv[0]);
  char buf[2048];
  FILE *f;
  if (!strcmp(argv[1], "-"))
    f = stdin;
  else
    f = fopen(argv[1], "r");
  if (!f) {
    perror("fopen");
    return 1;
  }
  while (fgets(buf, sizeof buf, f)) {
    char *p = strrchr(buf, '\n');
    if (!p) {
      dprintf(2, "error: line too long: %s\n", buf);
      continue;
    }
    *p = 0;
    if (remove(buf) != 0) {
      dprintf(2, "error: %s (%s)\n", strerror(errno), buf);
    } else {
      printf("removed %s\n", buf);
    }
  }
  if (f != stdin)
    fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e7 <main+0x37>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    1359 <main+0x1a9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe0a(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    121a <main+0x6a>
mov    0x2ddd(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x818(%rbp)
jmp    1235 <main+0x85>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd9(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x818(%rbp)
cmpq   $0x0,-0x818(%rbp)
jne    125b <main+0xab>
lea    0xdba(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1359 <main+0x1a9>
jmp    1260 <main+0xb0>
lea    -0x810(%rbp),%rdi
mov    -0x818(%rbp),%rdx
mov    $0x800,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     132f <main+0x17f>
lea    -0x810(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x820(%rbp)
cmpq   $0x0,-0x820(%rbp)
jne    12c7 <main+0x117>
lea    -0x810(%rbp),%rdx
mov    $0x2,%edi
lea    0xd4f(%rip),%rsi
mov    $0x0,%al
call   1070 <dprintf@plt>
jmp    1260 <main+0xb0>
mov    -0x820(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x810(%rbp),%rdi
call   1030 <remove@plt>
cmp    $0x0,%rax
je     1317 <main+0x167>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
movslq %eax,%rdx
lea    -0x810(%rbp),%rcx
mov    $0x2,%edi
lea    0xd19(%rip),%rsi
mov    $0x0,%al
call   1070 <dprintf@plt>
jmp    132a <main+0x17a>
lea    -0x810(%rbp),%rsi
lea    0xd0f(%rip),%rdi
call   1050 <printf@plt>
jmp    1260 <main+0xb0>
mov    -0x818(%rbp),%rax
mov    0x2cab(%rip),%rcx
cmp    (%rcx),%rax
je     1352 <main+0x1a2>
mov    -0x818(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
cmp    $0x2,%edi
jne    12bd <main+0x10d>
mov    0x8(%rsi),%rbx
lea    0xe2b(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     1300 <main+0x150>
lea    0xe16(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r14
test   %r14,%r14
je     1313 <main+0x163>
mov    %rsp,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12d6 <main+0x126>
mov    %rsp,%rbx
lea    0xde7(%rip),%r15
lea    0xe0a(%rip),%r12
mov    0x2da7(%rip),%rbp
lea    0xdec(%rip),%r13
jmp    1267 <main+0xb7>
nopw   0x0(%rax,%rax,1)
mov    $0x2,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <dprintf@plt>
mov    %rbx,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12d6 <main+0x126>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     1240 <main+0x90>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1030 <remove@plt>
test   %rax,%rax
je     12b0 <main+0x100>
mov    0x0(%rbp),%edi
call   10d0 <strerror@plt>
movslq %eax,%rdx
mov    $0x2,%edi
mov    %r13,%rsi
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <dprintf@plt>
jmp    1252 <main+0xa2>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
jmp    1252 <main+0xa2>
mov    (%rsi),%rdi
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <usage@plt>
mov    0x2d0b(%rip),%rax
xor    %ebx,%ebx
cmp    (%rax),%r14
je     12ec <main+0x13c>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ce1(%rip),%rax
mov    (%rax),%r14
test   %r14,%r14
jne    1200 <main+0x50>
lea    0xcea(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%ebx
jmp    12ec <main+0x13c>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [26 x i8] c"error: line too long: %s\0A\00"
@.str.4 = [16 x i8] c"error: %s (%s)\0A\00"
@errno = global i32 0
@.str.5 = [12 x i8] c"removed %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2048 x i8]
%7 = alloca i32*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @usage(i8* %14)
store i32 %15, i32* %3
br label %72
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %16
%23 = load i32*, i32** @stdin
store i32* %23, i32** %7
br label %29
24: ; preds = %16
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %7
br label %29
29: ; preds = %24, %22
%30 = load i32*, i32** %7
%31 = icmp ne i32* %30, null
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %72
34: ; preds = %29
br label %35
35: ; preds = %63, %45, %34
%36 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%37 = load i32*, i32** %7
%38 = call i64 @fgets(i8* %36, i32 2048, i32* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %64
40: ; preds = %35
%41 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%42 = call i8* @strrchr(i8* %41, i8 signext 10)
store i8* %42, i8** %8
%43 = load i8*, i8** %8
%44 = icmp ne i8* %43, null
br i1 %44, label %48, label %45
45: ; preds = %40
%46 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%47 = call i32 (i32, i8*, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %46)
br label %35
48: ; preds = %40
%49 = load i8*, i8** %8
store i8 0, i8* %49
%50 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%51 = call i64 @remove(i8* %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %60
53: ; preds = %48
%54 = load i32, i32* @errno
%55 = call i32 @strerror(i32 %54)
%56 = sext i32 %55 to i64
%57 = inttoptr i64 %56 to i8*
%58 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%59 = call i32 (i32, i8*, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %57, i8* %58)
br label %63
60: ; preds = %48
%61 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%62 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %60, %53
br label %35
64: ; preds = %35
%65 = load i32*, i32** %7
%66 = load i32*, i32** @stdin
%67 = icmp ne i32* %65, %66
br i1 %67, label %68, label %71
68: ; preds = %64
%69 = load i32*, i32** %7
%70 = call i32 @fclose(i32* %69)
br label %71
71: ; preds = %68, %64
store i32 0, i32* %3
br label %72
72: ; preds = %71, %32, %11
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [26 x i8] c"error: line too long: %s\0A\00"
@.str.4 = [16 x i8] c"error: %s (%s)\0A\00"
@errno = global i32 0
@.str.5 = [12 x i8] c"removed %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2048 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @usage(i8* %6)
br label %52
8: ; preds = %2
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = load i32*, i32** @stdin
br label %18
16: ; preds = %8
%17 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
%19 = phi i32* [ %17, %16 ], [ %15, %14 ]
%20 = icmp eq i32* %19, null
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = call i64 @fgets(i8* %9, i32 2048, i32* %19)
%23 = icmp eq i64 %22, 0
br i1 %23, label %45, label %26
24: ; preds = %18
%25 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %50
26: ; preds = %21, %42
%27 = call i8* @strrchr(i8* %9, i8 signext 10)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 (i32, i8*, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %9)
br label %42
31: ; preds = %26
store i8 0, i8* %27
%32 = call i64 @remove(i8* %9)
%33 = icmp eq i64 %32, 0
br i1 %33, label %40, label %34
34: ; preds = %31
%35 = load i32, i32* @errno
%36 = call i32 @strerror(i32 %35)
%37 = sext i32 %36 to i64
%38 = inttoptr i64 %37 to i8*
%39 = call i32 (i32, i8*, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %38, i8* %9)
br label %42
40: ; preds = %31
%41 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %9)
br label %42
42: ; preds = %34, %40, %29
%43 = call i64 @fgets(i8* %9, i32 2048, i32* %19)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %26
45: ; preds = %42, %21
%46 = load i32*, i32** @stdin
%47 = icmp eq i32* %19, %46
br i1 %47, label %50, label %48
48: ; preds = %45
%49 = call i32 @fclose(i32* %19)
br label %50
50: ; preds = %45, %48, %24
%51 = phi i32 [ 1, %24 ], [ 0, %48 ], [ 0, %45 ]
br label %52
52: ; preds = %50, %5
%53 = phi i32 [ %7, %5 ], [ %51, %50 ]
ret i32 %53
}