#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 */
int errno;
int /*<<< orphan*/ fatal(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fwide(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int /*<<< orphan*/ replFile(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wcs2mbs(int /*<<< orphan*/ *);
void replPath(wchar_t *path) {
  FILE *stream = fopen(wcs2mbs(path), "r");
  if (!stream) {
    int err = errno;
    fprintf(stderr, "\nerror: ");
    errno = err;
    perror(wcs2mbs(path));
    fatal(0);
  }
  fwide(stream, 1);
  if (fscanf(stream, "#!%*[^\012\015]"))
    ;
  replFile(stream, path);
  fclose(stream);
}


x86 assembly (clang, -O0):
<replPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <wcs2mbs@plt>
mov    %eax,%edi
lea    0xe52(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1206 <replPath+0x76>
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%ecx
mov    0x2deb(%rip),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <wcs2mbs@plt>
mov    %eax,%edi
call   1090 <perror@plt>
xor    %edi,%edi
call   10b0 <fatal@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1070 <fwide@plt>
mov    -0x10(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   1050 <fscanf@plt>
cmp    $0x0,%rax
je     1233 <replPath+0xa3>
jmp    1233 <replPath+0xa3>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10a0 <replFile@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replPath>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <wcs2mbs@plt>
lea    0xe5a(%rip),%rsi
mov    %eax,%edi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ed <replPath+0x5d>
mov    0x2e1c(%rip),%r15
mov    (%r15),%ebp
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
call   1060 <fprintf@plt>
mov    %ebp,(%r15)
mov    %r14,%rdi
call   1030 <wcs2mbs@plt>
mov    %eax,%edi
call   1090 <perror@plt>
xor    %edi,%edi
call   10b0 <fatal@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1070 <fwide@plt>
lea    0xe0a(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <replFile@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@errno = global i32 0
@stderr = global i32 0
@.str.1 = [9 x i8] c"\0Aerror: \00"
@.str.2 = [10 x i8] c"#!%*[^\0A\0D]\00"
define void @replPath(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = call i32 @wcs2mbs(i32* %5)
%7 = call i32* @fopen(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %19, label %10
10: ; preds = %1
%11 = load i32, i32* @errno
store i32 %11, i32* %4
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* %4
store i32 %14, i32* @errno
%15 = load i32*, i32** %2
%16 = call i32 @wcs2mbs(i32* %15)
%17 = call i32 @perror(i32 %16)
%18 = call i32 @fatal(i32 0)
br label %19
19: ; preds = %10, %1
%20 = load i32*, i32** %3
%21 = call i32 @fwide(i32* %20, i32 1)
%22 = load i32*, i32** %3
%23 = call i64 @fscanf(i32* %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19
br label %26
26: ; preds = %25, %19
%27 = load i32*, i32** %3
%28 = load i32*, i32** %2
%29 = call i32 @replFile(i32* %27, i32* %28)
%30 = load i32*, i32** %3
%31 = call i32 @fclose(i32* %30)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@errno = global i32 0
@stderr = global i32 0
@.str.1 = [9 x i8] c"\0Aerror: \00"
@.str.2 = [10 x i8] c"#!%*[^\0A\0D]\00"
define void @replPath(i32* %0) {
%2 = tail call i32 @wcs2mbs(i32* %0)
%3 = tail call i32* @fopen(i32 %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %12
5: ; preds = %1
%6 = load i32, i32* @errno
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32 %6, i32* @errno
%9 = tail call i32 @wcs2mbs(i32* %0)
%10 = tail call i32 @perror(i32 %9)
%11 = tail call i32 @fatal(i32 0)
br label %12
12: ; preds = %5, %1
%13 = tail call i32 @fwide(i32* %3, i32 1)
%14 = tail call i64 @fscanf(i32* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @replFile(i32* %3, i32* %0)
%16 = tail call i32 @fclose(i32* %3)
ret void
}