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

/* Variables and functions */
char *basename(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputwc(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
int main(int argc, char *argv[]) {
  FILE *fin, *fout;
  char *fname;
  wchar_t ch;
  const char *suffix = "_wchar";
  int l = strlen(suffix);
  int lf;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s filename\n", basename(argv[0]));
    return 1;
  }
  fin = fopen(argv[1], "r");
  if (fin == NULL) {
    perror("Cannot open input file");
    return 1;
  }
  lf = strlen(argv[1]);
  fname = malloc(lf + l + 1);
  strcpy(fname, argv[1]);
  strcpy(fname + lf, suffix);
  fout = fopen(fname, "w");
  free(fname);
  if (fout == NULL) {
    perror("Cannot open output file");
    return 1;
  }
  while (!feof(fin)) {
    ch = fgetc(fin);
    if (!feof(fin)) {
      fputwc(ch, fout);
    }
  }
  fclose(fin);
  fclose(fout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe23(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     122d <main+0x6d>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <basename@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xdeb(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    135a <main+0x19a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc9(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1268 <main+0xa8>
lea    0xdc4(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    135a <main+0x19a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%edi
add    -0x3c(%rbp),%edi
add    $0x1,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
movslq -0x40(%rbp),%rax
add    %rax,%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xd78(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
jne    12ef <main+0x12f>
lea    0xd56(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    135a <main+0x19a>
jmp    12f4 <main+0x134>
mov    -0x18(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1312 <main+0x152>
jmp    1341 <main+0x181>
mov    -0x18(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%eax
jne    133c <main+0x17c>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <fputwc@plt>
jmp    12f4 <main+0x134>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe2c(%rip),%rdi
call   1060 <strlen@plt>
cmp    $0x2,%ebx
jne    128e <main+0xce>
mov    %eax,%r15d
mov    0x8(%r14),%rdi
lea    0xe15(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     12d2 <main+0x112>
mov    %rax,%rbx
mov    0x8(%r14),%rdi
call   1060 <strlen@plt>
mov    %eax,%r12d
lea    (%r15,%r12,1),%edi
add    $0x1,%edi
call   10c0 <malloc@plt>
mov    %rax,%rbp
mov    0x8(%r14),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
movslq %r12d,%rdi
add    %rbp,%rdi
lea    0xdcb(%rip),%rsi
call   1040 <strcpy@plt>
lea    0xdf1(%rip),%rsi
mov    %rbp,%rdi
call   10d0 <fopen@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   1030 <free@plt>
test   %r14,%r14
je     12db <main+0x11b>
nopl   (%rax)
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
jne    12b7 <main+0xf7>
mov    %rbx,%rdi
call   1080 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
jne    1260 <main+0xa0>
mov    %ebp,%edi
mov    %r14,%rsi
call   1070 <fputwc@plt>
jmp    1260 <main+0xa0>
mov    0x2d4b(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rdi
call   10a0 <basename@plt>
lea    0xd61(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1090 <fprintf@plt>
mov    $0x1,%eax
jmp    12c9 <main+0x109>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd42(%rip),%rdi
jmp    12e2 <main+0x122>
lea    0xd52(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%eax
jmp    12c9 <main+0x109>

LLVM IR (-O0):
@.str = [7 x i8] c"_wchar\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"Usage: %s filename\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [23 x i8] c"Cannot open input file\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [24 x i8] c"Cannot open output file\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 i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %10
%13 = load i8*, i8** %10
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %11
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i8* @basename(i8* %21)
%23 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %22)
store i32 1, i32* %3
br label %84
24: ; preds = %2
%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.2, i64 0, i64 0))
store i32* %28, i32** %6
%29 = load i32*, i32** %6
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %84
33: ; preds = %24
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @strlen(i8* %36)
store i32 %37, i32* %12
%38 = load i32, i32* %12
%39 = load i32, i32* %11
%40 = add nsw i32 %38, %39
%41 = add nsw i32 %40, 1
%42 = call i8* @malloc(i32 %41)
store i8* %42, i8** %8
%43 = load i8*, i8** %8
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 @strcpy(i8* %43, i8* %46)
%48 = load i8*, i8** %8
%49 = load i32, i32* %12
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8*, i8** %10
%53 = call i32 @strcpy(i8* %51, i8* %52)
%54 = load i8*, i8** %8
%55 = call i32* @fopen(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %55, i32** %7
%56 = load i8*, i8** %8
%57 = call i32 @free(i8* %56)
%58 = load i32*, i32** %7
%59 = icmp eq i32* %58, null
br i1 %59, label %60, label %62
60: ; preds = %33
%61 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %84
62: ; preds = %33
br label %63
63: ; preds = %78, %62
%64 = load i32*, i32** %6
%65 = call i32 @feof(i32* %64)
%66 = icmp ne i32 %65, 0
%67 = xor i1 %66, true
br i1 %67, label %68, label %79
68: ; preds = %63
%69 = load i32*, i32** %6
%70 = call i32 @fgetc(i32* %69)
store i32 %70, i32* %9
%71 = load i32*, i32** %6
%72 = call i32 @feof(i32* %71)
%73 = icmp ne i32 %72, 0
br i1 %73, label %78, label %74
74: ; preds = %68
%75 = load i32, i32* %9
%76 = load i32*, i32** %7
%77 = call i32 @fputwc(i32 %75, i32* %76)
br label %78
78: ; preds = %74, %68
br label %63
79: ; preds = %63
%80 = load i32*, i32** %6
%81 = call i32 @fclose(i32* %80)
%82 = load i32*, i32** %7
%83 = call i32 @fclose(i32* %82)
store i32 0, i32* %3
br label %84
84: ; preds = %79, %60, %31, %17
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
@.str = [7 x i8] c"_wchar\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"Usage: %s filename\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [23 x i8] c"Cannot open input file\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [24 x i8] c"Cannot open output file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %0, 2
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i8* @basename(i8* %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %48
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %48
17: ; preds = %10
%18 = load i8*, i8** %11
%19 = tail call i32 @strlen(i8* %18)
%20 = add i32 %3, 1
%21 = add i32 %20, %19
%22 = tail call i8* @malloc(i32 %21)
%23 = load i8*, i8** %11
%24 = tail call i32 @strcpy(i8* %22, i8* %23)
%25 = sext i32 %19 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = tail call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%28 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%29 = tail call i32 @free(i8* %22)
%30 = icmp eq i32* %28, null
br i1 %30, label %34, label %31
31: ; preds = %17
%32 = tail call i32 @feof(i32* %13)
%33 = icmp eq i32 %32, 0
br i1 %33, label %36, label %45
34: ; preds = %17
%35 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %48
36: ; preds = %31, %42
%37 = tail call i32 @fgetc(i32* %13)
%38 = tail call i32 @feof(i32* %13)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = tail call i32 @fputwc(i32 %37, i32* %28)
br label %42
42: ; preds = %40, %36
%43 = tail call i32 @feof(i32* %13)
%44 = icmp eq i32 %43, 0
br i1 %44, label %36, label %45
45: ; preds = %42, %31
%46 = tail call i32 @fclose(i32* %13)
%47 = tail call i32 @fclose(i32* %28)
br label %48
48: ; preds = %45, %34, %15, %5
%49 = phi i32 [ 1, %5 ], [ 1, %15 ], [ 1, %34 ], [ 0, %45 ]
ret i32 %49
}