#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 == 0x0a)
        fputc(0x0d, temp_fp);
      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    13e9 <main+0x249>
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    13db <main+0x23b>
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    13db <main+0x23b>
jmp    12c3 <main+0x123>
mov    -0x128(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x134(%rbp)
mov    0x2d0c(%rip),%rcx
cmp    (%rcx),%eax
je     1319 <main+0x179>
cmpl   $0xa,-0x134(%rbp)
jne    1302 <main+0x162>
mov    -0x130(%rbp),%rsi
mov    $0xd,%edi
call   1060 <fputc@plt>
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    1385 <main+0x1e5>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd13(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xd19(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13db <main+0x23b>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <rename@plt>
cmp    $0x0,%rax
jge    13d6 <main+0x236>
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
lea    -0x120(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xcd4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xcc3(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13db <main+0x23b>
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    $0x128,%rsp
mov    %rsi,%rbp
cmp    $0x1,%edi
jg     11e0 <main+0x40>
mov    0x0(%rbp),%rdi
call   1080 <usage@plt>
movl   $0x0,0xc(%rsp)
mov    0xc(%rsp),%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edi,%eax
mov    %rax,0x18(%rsp)
mov    $0x1,%ebx
lea    0x20(%rsp),%r12
movl   $0x0,0xc(%rsp)
mov    %rbp,0x10(%rsp)
jmp    122a <main+0x8a>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
addl   $0x1,0xc(%rsp)
add    $0x1,%rbx
cmp    0x18(%rsp),%rbx
je     11ca <main+0x2a>
mov    0x0(%rbp,%rbx,8),%r13
mov    %r12,%rdi
lea    0xdc7(%rip),%rsi
mov    %r13,%rdx
call   10c0 <sprintf@plt>
mov    %r13,%rdi
lea    0xdc0(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1200 <main+0x60>
mov    %rax,%r14
mov    %r12,%rdi
lea    0xddf(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1300 <main+0x160>
mov    %rax,%r12
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%r15d
mov    0x2d63(%rip),%rbp
jmp    12a6 <main+0x106>
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%r15d
cmp    0x0(%rbp),%eax
je     12c0 <main+0x120>
cmp    $0xa,%r15d
jne    1290 <main+0xf0>
mov    $0xd,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
jmp    1290 <main+0xf0>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r13,%rdi
call   1030 <unlink@plt>
lea    0x20(%rsp),%r12
mov    %r12,%rdi
mov    %r13,%rsi
call   10b0 <rename@plt>
test   %rax,%rax
js     132a <main+0x18a>
mov    0x10(%rsp),%rbp
jmp    121f <main+0x7f>
nopw   0x0(%rax,%rax,1)
mov    %r12,%r15
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
lea    0xd31(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    121a <main+0x7a>
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
lea    0xd40(%rip),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xd29(%rip),%rdi
call   10a0 <perror@plt>
addl   $0x1,0xc(%rsp)
jmp    12ed <main+0x14d>

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 = %105, %20
%22 = load i32, i32* %6
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %108
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 %105
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 %105
57: ; preds = %44
br label %58
58: ; preds = %69, %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 %73
63: ; preds = %58
%64 = load i32, i32* %12
%65 = icmp eq i32 %64, 10
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = load i32*, i32** %11
%68 = call i32 @fputc(i32 13, i32* %67)
br label %69
69: ; preds = %66, %63
%70 = load i32, i32* %12
%71 = load i32*, i32** %11
%72 = call i32 @fputc(i32 %70, i32* %71)
br label %58
73: ; preds = %58
%74 = load i32*, i32** %10
%75 = call i32 @fclose(i32* %74)
%76 = load i32*, i32** %11
%77 = call i32 @fclose(i32* %76)
%78 = load i8*, i8** %8
%79 = call i32 @unlink(i8* %78)
%80 = icmp ne i32 %79, 0
%81 = xor i1 %80, true
%82 = zext i1 %81 to i32
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %91
84: ; preds = %73
%85 = load i32, i32* @stderr
%86 = load i8*, i8** %8
%87 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %86)
%88 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%89 = load i32, i32* %7
%90 = add nsw i32 %89, 1
store i32 %90, i32* %7
br label %105
91: ; preds = %73
%92 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%93 = load i8*, i8** %8
%94 = call i64 @rename(i8* %92, i8* %93)
%95 = icmp slt i64 %94, 0
br i1 %95, label %96, label %104
96: ; preds = %91
%97 = load i32, i32* @stderr
%98 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%99 = load i8*, i8** %8
%100 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %98, i8* %99)
%101 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%102 = load i32, i32* %7
%103 = add nsw i32 %102, 1
store i32 %103, i32* %7
br label %104
104: ; preds = %96, %91
br label %105
105: ; preds = %104, %84, %49, %38
%106 = load i32, i32* %6
%107 = add nsw i32 %106, 1
store i32 %107, i32* %6
br label %21
108: ; preds = %21
%109 = load i32, i32* %7
ret i32 %109
}

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 %60
9: ; preds = %2
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %9, %56
%12 = phi i64 [ 1, %9 ], [ %58, %56 ]
%13 = phi i32 [ 0, %9 ], [ %57, %56 ]
%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 %56
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 %45, 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 %56
35: ; preds = %26, %40
%36 = phi i32 [ %42, %40 ], [ %27, %26 ]
%37 = icmp eq i32 %36, 10
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @fputc(i32 13, i32* %24)
br label %40
40: ; preds = %38, %35
%41 = call i32 @fputc(i32 %36, i32* %24)
%42 = call i32 @fgetc(i32* %17)
%43 = load i32, i32* @EOF
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %35
45: ; preds = %40, %26
%46 = call i32 @fclose(i32* %17)
%47 = call i32 @fclose(i32* %24)
%48 = call i32 @unlink(i8* %15)
%49 = call i64 @rename(i8* %4, i8* %15)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %45
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %4, i8* %15)
%54 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%55 = add nsw i32 %13, 1
br label %56
56: ; preds = %45, %51, %30, %19
%57 = phi i32 [ %22, %19 ], [ %34, %30 ], [ %55, %51 ], [ %13, %45 ]
%58 = add nuw nsw i64 %12, 1
%59 = icmp eq i64 %58, %10
br i1 %59, label %60, label %11
60: ; preds = %56, %6
%61 = phi i32 [ 0, %6 ], [ %57, %56 ]
ret i32 %61
}