#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ mktemp(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  FILE *dosfile;
  FILE *unixfile;
  int idx;
  int buf;
  char dosname[48];
  if (argc == 1) {
    printf("Usage :  unix2dos  file1 [file2 ... fileN]\n");
    printf("         Wildcards in file names will be expanded.\n");
    exit(1);
  }
  for (idx = 1; idx < argc; idx++) {
    printf("%s\n", argv[idx]);
    unixfile = fopen(argv[idx], "rb");
    strcpy(dosname, "u2dXXXXX");
    mktemp(dosname);
    dosfile = fopen(dosname, "wb");
    while ((buf = getc(unixfile)) != EOF) {
      if (buf != '\n')
        putc(buf, dosfile);
      else {
        putc('\r', dosfile);
        putc('\n', dosfile);
      }
    }
    fclose(dosfile);
    fclose(unixfile);
    remove(argv[idx]);
    rename(dosname, argv[idx]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11e6 <main+0x46>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12fc <main+0x15c>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe3e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x60(%rbp),%rdi
call   10c0 <mktemp@plt>
lea    -0x60(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   10b0 <getc@plt>
mov    %eax,-0x28(%rbp)
mov    0x2d79(%rip),%rcx
cmp    (%rcx),%eax
je     12b6 <main+0x116>
cmpl   $0xa,-0x28(%rbp)
je     1295 <main+0xf5>
mov    -0x28(%rbp),%eax
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1070 <putc@plt>
jmp    12b1 <main+0x111>
mov    -0x18(%rbp),%rsi
mov    $0xd,%edi
call   1070 <putc@plt>
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1070 <putc@plt>
jmp    125c <main+0xbc>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <remove@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1090 <rename@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ed <main+0x4d>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
cmp    $0x1,%edi
je     12a3 <main+0x103>
jle    1292 <main+0xf2>
mov    %rsi,%rbx
mov    %edi,%eax
mov    %rax,0x8(%rsp)
mov    $0x1,%r13d
lea    0x10(%rsp),%r12
mov    0x2e0f(%rip),%r15
jmp    1214 <main+0x74>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    (%rbx,%r13,8),%rdi
call   1030 <remove@plt>
mov    (%rbx,%r13,8),%rsi
mov    %r12,%rdi
call   1090 <rename@plt>
add    $0x1,%r13
cmp    0x8(%rsp),%r13
je     1292 <main+0xf2>
mov    (%rbx,%r13,8),%rdi
call   1050 <puts@plt>
mov    (%rbx,%r13,8),%rdi
lea    0xdd8(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbp
mov    %r12,%rdi
lea    0xdc9(%rip),%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
call   10c0 <mktemp@plt>
mov    %r12,%rdi
lea    0xdbb(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
jmp    126b <main+0xcb>
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %r14,%rsi
call   1070 <putc@plt>
mov    %rbp,%rdi
call   10b0 <getc@plt>
cmp    (%r15),%eax
je     11e0 <main+0x40>
cmp    $0xa,%eax
jne    1260 <main+0xc0>
mov    $0xd,%edi
mov    %r14,%rsi
call   1070 <putc@plt>
mov    $0xa,%al
jmp    1260 <main+0xc0>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd65(%rip),%rdi
call   1050 <puts@plt>
lea    0xd84(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"Usage : unix2dos file1 [file2 ... fileN]\0A\00"
@.str.1 = [52 x i8] c" Wildcards in file names will be expanded.\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [9 x i8] c"u2dXXXXX\00"
@.str.5 = [3 x i8] c"wb\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [48 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
store i32 1, i32* %8
br label %18
18: ; preds = %78, %17
%19 = load i32, i32* %8
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %81
22: ; preds = %18
%23 = load i8**, i8*** %5
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = load i8**, i8*** %5
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %34, i32** %7
%35 = getelementptr inbounds [48 x i8], [48 x i8]* %10, i64 0, i64 0
%36 = call i32 @strcpy(i8* %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%37 = getelementptr inbounds [48 x i8], [48 x i8]* %10, i64 0, i64 0
%38 = call i32 @mktemp(i8* %37)
%39 = getelementptr inbounds [48 x i8], [48 x i8]* %10, i64 0, i64 0
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %40, i32** %6
br label %41
41: ; preds = %59, %22
%42 = load i32*, i32** %7
%43 = call i32 @getc(i32* %42)
store i32 %43, i32* %9
%44 = load i32, i32* @EOF
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %60
46: ; preds = %41
%47 = load i32, i32* %9
%48 = icmp ne i32 %47, 10
br i1 %48, label %49, label %54
49: ; preds = %46
%50 = load i32, i32* %9
%51 = trunc i32 %50 to i8
%52 = load i32*, i32** %6
%53 = call i32 @putc(i8 signext %51, i32* %52)
br label %59
54: ; preds = %46
%55 = load i32*, i32** %6
%56 = call i32 @putc(i8 signext 13, i32* %55)
%57 = load i32*, i32** %6
%58 = call i32 @putc(i8 signext 10, i32* %57)
br label %59
59: ; preds = %54, %49
br label %41
60: ; preds = %41
%61 = load i32*, i32** %6
%62 = call i32 @fclose(i32* %61)
%63 = load i32*, i32** %7
%64 = call i32 @fclose(i32* %63)
%65 = load i8**, i8*** %5
%66 = load i32, i32* %8
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8*, i8** %65, i64 %67
%69 = load i8*, i8** %68
%70 = call i32 @remove(i8* %69)
%71 = getelementptr inbounds [48 x i8], [48 x i8]* %10, i64 0, i64 0
%72 = load i8**, i8*** %5
%73 = load i32, i32* %8
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8*, i8** %72, i64 %74
%76 = load i8*, i8** %75
%77 = call i32 @rename(i8* %71, i8* %76)
br label %78
78: ; preds = %60
%79 = load i32, i32* %8
%80 = add nsw i32 %79, 1
store i32 %80, i32* %8
br label %18
81: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [9 x i8] c"u2dXXXXX\00"
@.str.5 = [3 x i8] c"wb\00"
@EOF = global i32 0
@str = [43 x i8] c"Usage : unix2dos file1 [file2 ... fileN]\00"
@str.6 = [51 x i8] c" Wildcards in file names will be expanded.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [48 x i8]
%4 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 1
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %49
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %14
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.6, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8, %40
%15 = phi i64 [ 1, %8 ], [ %47, %40 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 %15
%17 = load i8*, i8** %16
%18 = call i32 @puts(i8* dereferenceable(1) %17)
%19 = load i8*, i8** %16
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @mktemp(i8* %4)
%23 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%24 = call i32 @getc(i32* %20)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %40, label %27
27: ; preds = %14, %34
%28 = phi i32 [ %37, %34 ], [ %24, %14 ]
%29 = icmp eq i32 %28, 10
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = trunc i32 %28 to i8
br label %34
32: ; preds = %27
%33 = call i32 @putc(i8 signext 13, i32* %23)
br label %34
34: ; preds = %32, %30
%35 = phi i8 [ 10, %32 ], [ %31, %30 ]
%36 = call i32 @putc(i8 signext %35, i32* %23)
%37 = call i32 @getc(i32* %20)
%38 = load i32, i32* @EOF
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %27
40: ; preds = %34, %14
%41 = call i32 @fclose(i32* %23)
%42 = call i32 @fclose(i32* %20)
%43 = load i8*, i8** %16
%44 = call i32 @remove(i8* %43)
%45 = load i8*, i8** %16
%46 = call i32 @rename(i8* %4, i8* %45)
%47 = add nuw nsw i64 %15, 1
%48 = icmp eq i64 %47, %9
br i1 %48, label %49, label %14
49: ; preds = %40, %6
ret i32 0
}