#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*/ iconv_t;

/* Variables and functions */
int /*<<< orphan*/ CODESET;
int /*<<< orphan*/ die(char *);
size_t iconv(int /*<<< orphan*/, char **, size_t *, char **, size_t *);
int /*<<< orphan*/ iconv_close(int /*<<< orphan*/);
int /*<<< orphan*/ iconv_open(char *, char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *nl_langinfo(int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *make_unix_pathname(char *org_fn) {
  char tmp[256];
  strcpy(tmp, org_fn);
  for (int i = 0; tmp[i]; i++) {
    if (tmp[i] == '/')
      tmp[i] = '_';
  }
  for (int i = 0; tmp[i]; i++) {
    if (tmp[i] == '\\')
      tmp[i] = '/';
  }
  char tmpout[256];
  char to_code[64];
  strcpy(to_code, nl_langinfo(CODESET));
  strcat(to_code, "//TRANSLIT");
  iconv_t cd = iconv_open(to_code, "ISO8859-1");
  if (!cd)
    die("iconv_open");
  size_t inbl = strlen(tmp), outbl = 255;
  char *inbuf = &(tmp[0]), *outbuf = &(tmpout[0]);
  memset(tmpout, 0, 256);
  if (iconv(cd, &inbuf, &inbl, &outbuf, &outbl) == (size_t)-1)
    die("iconv");
  char *rv = malloc(strlen(tmpout) + 1);
  if (!rv)
    die("malloc");
  strcpy(rv, tmpout);
  iconv_close(cd);
  return rv;
}


x86 assembly (clang, -O0):
<make_unix_pathname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x114(%rbp)
movslq -0x114(%rbp),%rax
cmpb   $0x0,-0x110(%rbp,%rax,1)
je     121e <make_unix_pathname+0x7e>
movslq -0x114(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    1205 <make_unix_pathname+0x65>
movslq -0x114(%rbp),%rax
movb   $0x5f,-0x110(%rbp,%rax,1)
5f
jmp    120a <make_unix_pathname+0x6a>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    11c9 <make_unix_pathname+0x29>
movl   $0x0,-0x118(%rbp)
movslq -0x118(%rbp),%rax
cmpb   $0x0,-0x110(%rbp,%rax,1)
je     127d <make_unix_pathname+0xdd>
movslq -0x118(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x5c,%eax
jne    1264 <make_unix_pathname+0xc4>
movslq -0x118(%rbp),%rax
movb   $0x2f,-0x110(%rbp,%rax,1)
2f
jmp    1269 <make_unix_pathname+0xc9>
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    1228 <make_unix_pathname+0x88>
lea    -0x260(%rbp),%rax
mov    %rax,-0x298(%rbp)
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
call   1080 <nl_langinfo@plt>
mov    -0x298(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
lea    -0x260(%rbp),%rdi
lea    0xd4a(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0x260(%rbp),%rdi
lea    0xd42(%rip),%rsi
call   10c0 <iconv_open@plt>
mov    %eax,-0x264(%rbp)
cmpl   $0x0,-0x264(%rbp)
jne    12ed <make_unix_pathname+0x14d>
lea    0xd2d(%rip),%rdi
call   10a0 <die@plt>
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
cltq
mov    %rax,-0x270(%rbp)
movq   $0xff,-0x278(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x280(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x288(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    -0x264(%rbp),%edi
lea    -0x280(%rbp),%rsi
lea    -0x270(%rbp),%rdx
lea    -0x288(%rbp),%rcx
lea    -0x278(%rbp),%r8
call   1040 <iconv@plt>
cmp    $0xffffffffffffffff,%rax
jne    1379 <make_unix_pathname+0x1d9>
lea    0xcac(%rip),%rdi
call   10a0 <die@plt>
lea    -0x220(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x290(%rbp)
cmpq   $0x0,-0x290(%rbp)
jne    13b0 <make_unix_pathname+0x210>
lea    0xc7b(%rip),%rdi
call   10a0 <die@plt>
mov    -0x290(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x264(%rbp),%edi
call   1090 <iconv_close@plt>
mov    -0x290(%rbp),%rax
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_unix_pathname>:
push   %rbp
push   %rbx
sub    $0x268,%rsp
mov    %rdi,%rsi
lea    0x160(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
jmp    11c7 <make_unix_pathname+0x27>
xchg   %ax,%ax
movb   $0x5f,(%rbx)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2f,%al
je     11c0 <make_unix_pathname+0x20>
test   %al,%al
jne    11c3 <make_unix_pathname+0x23>
lea    0x160(%rsp),%rax
jmp    11e7 <make_unix_pathname+0x47>
nopl   0x0(%rax)
movb   $0x2f,(%rax)
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x5c,%cl
je     11e0 <make_unix_pathname+0x40>
test   %cl,%cl
jne    11e3 <make_unix_pathname+0x43>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
call   1080 <nl_langinfo@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
lea    0xde8(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
lea    0xde4(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <iconv_open@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1241 <make_unix_pathname+0xa1>
lea    0xdd9(%rip),%rdi
call   10a0 <die@plt>
lea    0x160(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
mov    %rax,0x18(%rsp)
movq   $0xff,0x10(%rsp)
mov    %rbx,0x8(%rsp)
lea    0x60(%rsp),%rdi
mov    %rdi,(%rsp)
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    0x8(%rsp),%rsi
lea    0x18(%rsp),%rdx
mov    %rsp,%rcx
lea    0x10(%rsp),%r8
mov    %ebp,%edi
call   1040 <iconv@plt>
cmp    $0xffffffffffffffff,%rax
jne    12a6 <make_unix_pathname+0x106>
lea    0xd7f(%rip),%rdi
call   10a0 <die@plt>
lea    0x60(%rsp),%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    12cc <make_unix_pathname+0x12c>
lea    0xd5f(%rip),%rdi
call   10a0 <die@plt>
lea    0x60(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %ebp,%edi
call   1090 <iconv_close@plt>
mov    %rbx,%rax
add    $0x268,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@CODESET = global i32 0
@.str = [11 x i8] c"//TRANSLIT\00"
@.str.1 = [10 x i8] c"ISO8859-1\00"
@.str.2 = [11 x i8] c"iconv_open\00"
@.str.3 = [6 x i8] c"iconv\00"
@.str.4 = [7 x i8] c"malloc\00"
define i8* @make_unix_pathname(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca [64 x i8]
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %2
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%15 = load i8*, i8** %2
%16 = call i32 @strcpy(i8* %14, i8* %15)
store i32 0, i32* %4
br label %17
17: ; preds = %35, %1
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp ne i8 %21, 0
br i1 %22, label %23, label %38
23: ; preds = %17
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 47
br i1 %29, label %30, label %34
30: ; preds = %23
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %32
store i8 95, i8* %33
br label %34
34: ; preds = %30, %23
br label %35
35: ; preds = %34
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %17
38: ; preds = %17
store i32 0, i32* %5
br label %39
39: ; preds = %57, %38
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = icmp ne i8 %43, 0
br i1 %44, label %45, label %60
45: ; preds = %39
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 92
br i1 %51, label %52, label %56
52: ; preds = %45
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %54
store i8 47, i8* %55
br label %56
56: ; preds = %52, %45
br label %57
57: ; preds = %56
%58 = load i32, i32* %5
%59 = add nsw i32 %58, 1
store i32 %59, i32* %5
br label %39
60: ; preds = %39
%61 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%62 = load i32, i32* @CODESET
%63 = call i8* @nl_langinfo(i32 %62)
%64 = call i32 @strcpy(i8* %61, i8* %63)
%65 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%66 = call i32 @strcat(i8* %65, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%67 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%68 = call i32 @iconv_open(i8* %67, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 %68, i32* %8
%69 = load i32, i32* %8
%70 = icmp ne i32 %69, 0
br i1 %70, label %73, label %71
71: ; preds = %60
%72 = call i32 @die(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %73
73: ; preds = %71, %60
%74 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%75 = call i32 @strlen(i8* %74)
%76 = sext i32 %75 to i64
store i64 %76, i64* %9
store i64 255, i64* %10
%77 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
store i8* %77, i8** %11
%78 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
store i8* %78, i8** %12
%79 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%80 = call i32 @memset(i8* %79, i32 0, i32 256)
%81 = load i32, i32* %8
%82 = call i64 @iconv(i32 %81, i8** %11, i64* %9, i8** %12, i64* %10)
%83 = icmp eq i64 %82, -1
br i1 %83, label %84, label %86
84: ; preds = %73
%85 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %86
86: ; preds = %84, %73
%87 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%88 = call i32 @strlen(i8* %87)
%89 = add nsw i32 %88, 1
%90 = call i8* @malloc(i32 %89)
store i8* %90, i8** %13
%91 = load i8*, i8** %13
%92 = icmp ne i8* %91, null
br i1 %92, label %95, label %93
93: ; preds = %86
%94 = call i32 @die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %95
95: ; preds = %93, %86
%96 = load i8*, i8** %13
%97 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%98 = call i32 @strcpy(i8* %96, i8* %97)
%99 = load i32, i32* %8
%100 = call i32 @iconv_close(i32 %99)
%101 = load i8*, i8** %13
ret i8* %101
}

LLVM IR (-O2):
@CODESET = global i32 0
@.str = [11 x i8] c"//TRANSLIT\00"
@.str.1 = [10 x i8] c"ISO8859-1\00"
@.str.2 = [11 x i8] c"iconv_open\00"
@.str.3 = [6 x i8] c"iconv\00"
@.str.4 = [7 x i8] c"malloc\00"
define i8* @make_unix_pathname(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = alloca [64 x i8]
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%10 = call i32 @strcpy(i8* %9, i8* %0)
br label %11
11: ; preds = %16, %1
%12 = phi i64 [ %17, %16 ], [ 0, %1 ]
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %12
%14 = load i8, i8* %13
switch i8 %14, label %16 [
i8 0, label %18
i8 47, label %15
]
15: ; preds = %11
store i8 95, i8* %13
br label %16
16: ; preds = %11, %15
%17 = add nuw i64 %12, 1
br label %11
18: ; preds = %11, %32
%19 = phi i64 [ %33, %32 ], [ 0, %11 ]
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
switch i8 %21, label %32 [
i8 0, label %22
i8 92, label %31
]
22: ; preds = %18
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%25 = load i32, i32* @CODESET
%26 = call i8* @nl_langinfo(i32 %25)
%27 = call i32 @strcpy(i8* %24, i8* %26)
%28 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @iconv_open(i8* %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %34, label %36
31: ; preds = %18
store i8 47, i8* %20
br label %32
32: ; preds = %18, %31
%33 = add nuw i64 %19, 1
br label %18
34: ; preds = %22
%35 = call i32 @die(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %22
%37 = bitcast i64* %5 to i8*
%38 = call i32 @strlen(i8* %9)
%39 = sext i32 %38 to i64
store i64 %39, i64* %5
%40 = bitcast i64* %6 to i8*
store i64 255, i64* %6
%41 = bitcast i8** %7 to i8*
store i8* %9, i8** %7
%42 = bitcast i8** %8 to i8*
store i8* %23, i8** %8
%43 = call i32 @memset(i8* %23, i32 0, i32 256)
%44 = call i64 @iconv(i32 %29, i8** %7, i64* %5, i8** %8, i64* %6)
%45 = icmp eq i64 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %36
%47 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %46, %36
%49 = call i32 @strlen(i8* %23)
%50 = add nsw i32 %49, 1
%51 = call i8* @malloc(i32 %50)
%52 = icmp eq i8* %51, null
br i1 %52, label %53, label %55
53: ; preds = %48
%54 = call i32 @die(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %53, %48
%56 = call i32 @strcpy(i8* %51, i8* %23)
%57 = call i32 @iconv_close(i32 %29)
ret i8* %51
}