#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int argi;
  int num_fail = 0;
  char *input_file_name;
  char temp_file_name[256];
  FILE *input_fp;
  FILE *temp_fp;
  int c;
  if (argc < 2)
    usage(argv[0]);
  for (argi = 1; argi < argc; argi++) {
    input_file_name = argv[argi];
    sprintf(temp_file_name, "%s.__d2u__", input_file_name);
    input_fp = fopen(input_file_name, "rb");
    if (input_fp == 0) {
      fprintf(stderr, "Couldn't open input file \"%s\" for read.  Exiting.\n",
              input_file_name);
      num_fail++;
      continue;
    }
    temp_fp = fopen(temp_file_name, "wb");
    if (temp_fp == 0) {
      fprintf(stderr, "Couldn't open temp file \"%s\" for write.  Exiting.\n",
              temp_file_name);
      fclose(input_fp);
      num_fail++;
      continue;
    }
    while ((c = fgetc(input_fp)) != EOF)
      if (c != 0x0d)
        fputc(c, temp_fp);
    fclose(input_fp);
    fclose(temp_fp);
    if (!unlink(input_file_name) < 0) {
      fprintf(stderr, "Could not unlink %s", input_file_name);
      perror(": ");
      num_fail++;
      continue;
    }
    if (rename(temp_file_name, input_file_name) < 0) {
      fprintf(stderr, "Could not rename %s to %s", temp_file_name,
              input_file_name);
      perror(": ");
      num_fail++;
    }
  }
  return num_fail;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d6 <main+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <usage@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13d8 <main+0x238>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdf5(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    125e <main+0xbe>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdc5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13ca <main+0x22a>
lea    -0x120(%rbp),%rdi
lea    0xdd5(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
jne    12be <main+0x11e>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
lea    -0x120(%rbp),%rdx
lea    0xda7(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x128(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13ca <main+0x22a>
jmp    12c3 <main+0x123>
mov    -0x128(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x134(%rbp)
mov    0x2d0c(%rip),%rcx
cmp    (%rcx),%eax
je     1308 <main+0x168>
cmpl   $0xd,-0x134(%rbp)
je     1303 <main+0x163>
mov    -0x134(%rbp),%edi
mov    -0x130(%rbp),%rsi
call   1060 <fputc@plt>
jmp    12c3 <main+0x123>
mov    -0x128(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x130(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x0,%eax
jge    1374 <main+0x1d4>
mov    0x2c92(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd24(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xd2a(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13ca <main+0x22a>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <rename@plt>
cmp    $0x0,%rax
jge    13c5 <main+0x225>
mov    0x2c43(%rip),%rax
mov    (%rax),%edi
lea    -0x120(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xce5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xcd4(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13ca <main+0x22a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11dd <main+0x3d>
mov    -0x18(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     11df <main+0x3f>
mov    (%rbx),%rdi
call   1080 <usage@plt>
movl   $0x0,0x4(%rsp)
mov    0x4(%rsp),%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edi,%eax
mov    %rax,0x8(%rsp)
mov    $0x1,%r15d
lea    0x10(%rsp),%r13
movl   $0x0,0x4(%rsp)
jmp    1237 <main+0x97>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
call   1030 <unlink@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   10b0 <rename@plt>
test   %rax,%rax
js     12fc <main+0x15c>
add    $0x1,%r15
cmp    0x8(%rsp),%r15
je     11c9 <main+0x29>
mov    (%rbx,%r15,8),%rbp
mov    %r13,%rdi
lea    0xdbb(%rip),%rsi
mov    %rbp,%rdx
call   10c0 <sprintf@plt>
mov    %rbp,%rdi
lea    0xdb4(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12b0 <main+0x110>
mov    %rax,%r14
mov    %r13,%rdi
lea    0xdd3(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12d0 <main+0x130>
mov    %rax,%r12
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    0x2d59(%rip),%rcx
cmp    (%rcx),%eax
je     1200 <main+0x60>
cmp    $0xd,%eax
je     1280 <main+0xe0>
mov    %eax,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
jmp    1280 <main+0xe0>
nopl   0x0(%rax,%rax,1)
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
lea    0xd4e(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12f2 <main+0x152>
nopl   0x0(%rax)
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
lea    0xd64(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
addl   $0x1,0x4(%rsp)
jmp    122c <main+0x8c>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
lea    0xd6e(%rip),%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xd57(%rip),%rdi
call   10a0 <perror@plt>
jmp    12f2 <main+0x152>

LLVM IR (-O0):
@.str = [11 x i8] c"%s.__d2u__\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [51 x i8] c"Couldn't open input file \22%s\22 for read. Exiting.\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [51 x i8] c"Couldn't open temp file \22%s\22 for write. Exiting.\0A\00"
@EOF = global i32 0
@.str.5 = [20 x i8] c"Could not unlink %s\00"
@.str.6 = [3 x i8] c": \00"
@.str.7 = [26 x i8] c"Could not rename %s to %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [256 x i8]
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @usage(i8* %18)
br label %20
20: ; preds = %15, %2
store i32 1, i32* %6
br label %21
21: ; preds = %103, %20
%22 = load i32, i32* %6
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %106
25: ; preds = %21
%26 = load i8**, i8*** %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
store i8* %30, i8** %8
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%32 = load i8*, i8** %8
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %8
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %35, i32** %10
%36 = load i32*, i32** %10
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %44
38: ; preds = %25
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %8
%41 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %103
44: ; preds = %25
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %46, i32** %11
%47 = load i32*, i32** %11
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %57
49: ; preds = %44
%50 = load i32, i32* @stderr
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%52 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %51)
%53 = load i32*, i32** %10
%54 = call i32 @fclose(i32* %53)
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %103
57: ; preds = %44
br label %58
58: ; preds = %70, %57
%59 = load i32*, i32** %10
%60 = call i32 @fgetc(i32* %59)
store i32 %60, i32* %12
%61 = load i32, i32* @EOF
%62 = icmp ne i32 %60, %61
br i1 %62, label %63, label %71
63: ; preds = %58
%64 = load i32, i32* %12
%65 = icmp ne i32 %64, 13
br i1 %65, label %66, label %70
66: ; preds = %63
%67 = load i32, i32* %12
%68 = load i32*, i32** %11
%69 = call i32 @fputc(i32 %67, i32* %68)
br label %70
70: ; preds = %66, %63
br label %58
71: ; preds = %58
%72 = load i32*, i32** %10
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %11
%75 = call i32 @fclose(i32* %74)
%76 = load i8*, i8** %8
%77 = call i32 @unlink(i8* %76)
%78 = icmp ne i32 %77, 0
%79 = xor i1 %78, true
%80 = zext i1 %79 to i32
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %89
82: ; preds = %71
%83 = load i32, i32* @stderr
%84 = load i8*, i8** %8
%85 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %84)
%86 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%87 = load i32, i32* %7
%88 = add nsw i32 %87, 1
store i32 %88, i32* %7
br label %103
89: ; preds = %71
%90 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%91 = load i8*, i8** %8
%92 = call i64 @rename(i8* %90, i8* %91)
%93 = icmp slt i64 %92, 0
br i1 %93, label %94, label %102
94: ; preds = %89
%95 = load i32, i32* @stderr
%96 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%97 = load i8*, i8** %8
%98 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %96, i8* %97)
%99 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%100 = load i32, i32* %7
%101 = add nsw i32 %100, 1
store i32 %101, i32* %7
br label %102
102: ; preds = %94, %89
br label %103
103: ; preds = %102, %82, %49, %38
%104 = load i32, i32* %6
%105 = add nsw i32 %104, 1
store i32 %105, i32* %6
br label %21
106: ; preds = %21
%107 = load i32, i32* %7
ret i32 %107
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s.__d2u__\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [51 x i8] c"Couldn't open input file \22%s\22 for read. Exiting.\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [51 x i8] c"Couldn't open temp file \22%s\22 for write. Exiting.\0A\00"
@EOF = global i32 0
@.str.6 = [3 x i8] c": \00"
@.str.7 = [26 x i8] c"Could not rename %s to %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
br label %59
9: ; preds = %2
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %9, %55
%12 = phi i64 [ 1, %9 ], [ %57, %55 ]
%13 = phi i32 [ 0, %9 ], [ %56, %55 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 %12
%15 = load i8*, i8** %14
%16 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %11
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%22 = add nsw i32 %13, 1
br label %55
23: ; preds = %11
%24 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %30, label %26
26: ; preds = %23
%27 = call i32 @fgetc(i32* %17)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %44, label %35
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%33 = call i32 @fclose(i32* %17)
%34 = add nsw i32 %13, 1
br label %55
35: ; preds = %26, %40
%36 = phi i32 [ %41, %40 ], [ %27, %26 ]
%37 = icmp eq i32 %36, 13
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = call i32 @fputc(i32 %36, i32* %24)
br label %40
40: ; preds = %38, %35
%41 = call i32 @fgetc(i32* %17)
%42 = load i32, i32* @EOF
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %35
44: ; preds = %40, %26
%45 = call i32 @fclose(i32* %17)
%46 = call i32 @fclose(i32* %24)
%47 = call i32 @unlink(i8* %15)
%48 = call i64 @rename(i8* %4, i8* %15)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %44
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %4, i8* %15)
%53 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%54 = add nsw i32 %13, 1
br label %55
55: ; preds = %44, %50, %30, %19
%56 = phi i32 [ %22, %19 ], [ %34, %30 ], [ %54, %50 ], [ %13, %44 ]
%57 = add nuw nsw i64 %12, 1
%58 = icmp eq i64 %57, %10
br i1 %58, label %59, label %11
59: ; preds = %55, %6
%60 = phi i32 [ 0, %6 ], [ %56, %55 ]
ret i32 %60
}