#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 */
struct lconv {
  char *decimal_point;
};

/* Variables and functions */
struct lconv *localeconv();
size_t strlen(char const *);
scalar_t__ strncmp(char *, char const *, size_t);
void wcsutil_locale_to_dot(char *buf) {
  struct lconv *locale_data = localeconv();
  const char *decimal_point = locale_data->decimal_point;
  if (decimal_point[0] != '.' || decimal_point[1] != 0) {
    size_t decimal_point_len = strlen(decimal_point);
    char *inbuf = buf;
    char *outbuf = buf;
    for (; *inbuf; ++inbuf) {
      if (strncmp(inbuf, decimal_point, decimal_point_len) == 0) {
        *outbuf++ = '.';
        inbuf += decimal_point_len - 1;
      } else {
        *outbuf++ = *inbuf;
      }
    }
    *outbuf = '\0';
  }
}


x86 assembly (clang, -O0):
<wcsutil_locale_to_dot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <localeconv@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1173 <wcsutil_locale_to_dot+0x43>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1213 <wcsutil_locale_to_dot+0xe3>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     120c <wcsutil_locale_to_dot+0xdc>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11df <wcsutil_locale_to_dot+0xaf>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x2e,(%rax)
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11f6 <wcsutil_locale_to_dot+0xc6>
mov    -0x28(%rbp),%rax
mov    (%rax),%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
jmp    11fb <wcsutil_locale_to_dot+0xcb>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1190 <wcsutil_locale_to_dot+0x60>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsutil_locale_to_dot>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r12
xor    %eax,%eax
call   1040 <localeconv@plt>
mov    (%rax),%r14
cmpb   $0x2e,(%r14)
jne    1153 <wcsutil_locale_to_dot+0x23>
cmpb   $0x0,0x1(%r14)
je     11b7 <wcsutil_locale_to_dot+0x87>
mov    %r14,%rdi
call   1050 <strlen@plt>
cmpb   $0x0,(%r12)
je     11b2 <wcsutil_locale_to_dot+0x82>
mov    %rax,%r15
mov    %rax,%r13
add    $0xffffffffffffffff,%r13
mov    %r12,%rbx
jmp    1195 <wcsutil_locale_to_dot+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
mov    %al,(%r12)
add    $0x1,%r12
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     11b2 <wcsutil_locale_to_dot+0x82>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1180 <wcsutil_locale_to_dot+0x50>
movb   $0x2e,(%r12)
add    %r13,%rbx
jmp    1187 <wcsutil_locale_to_dot+0x57>
movb   $0x0,(%r12)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.lconv = type { i8* }
define void @wcsutil_locale_to_dot(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.lconv*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %2
%8 = call %struct.lconv* (...) @localeconv()
store %struct.lconv* %8, %struct.lconv** %3
%9 = load %struct.lconv*, %struct.lconv** %3
%10 = getelementptr inbounds %struct.lconv, %struct.lconv* %9, i32 0, i32 0
%11 = load i8*, i8** %10
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 46
br i1 %16, label %23, label %17
17: ; preds = %1
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %56
23: ; preds = %17, %1
%24 = load i8*, i8** %4
%25 = call i64 @strlen(i8* %24)
store i64 %25, i64* %5
%26 = load i8*, i8** %2
store i8* %26, i8** %6
%27 = load i8*, i8** %2
store i8* %27, i8** %7
br label %28
28: ; preds = %51, %23
%29 = load i8*, i8** %6
%30 = load i8, i8* %29
%31 = icmp ne i8 %30, 0
br i1 %31, label %32, label %54
32: ; preds = %28
%33 = load i8*, i8** %6
%34 = load i8*, i8** %4
%35 = load i64, i64* %5
%36 = call i64 @strncmp(i8* %33, i8* %34, i64 %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %32
%39 = load i8*, i8** %7
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %7
store i8 46, i8* %39
%41 = load i64, i64* %5
%42 = sub i64 %41, 1
%43 = load i8*, i8** %6
%44 = getelementptr inbounds i8, i8* %43, i64 %42
store i8* %44, i8** %6
br label %50
45: ; preds = %32
%46 = load i8*, i8** %6
%47 = load i8, i8* %46
%48 = load i8*, i8** %7
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %7
store i8 %47, i8* %48
br label %50
50: ; preds = %45, %38
br label %51
51: ; preds = %50
%52 = load i8*, i8** %6
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %6
br label %28
54: ; preds = %28
%55 = load i8*, i8** %7
store i8 0, i8* %55
br label %56
56: ; preds = %54, %17
ret void
}

LLVM IR (-O2):
%struct.lconv = type { i8* }
define void @wcsutil_locale_to_dot(i8* %0) {
%2 = tail call %struct.lconv* (...) @localeconv()
%3 = getelementptr inbounds %struct.lconv, %struct.lconv* %2, i64 0, i32 0
%4 = load i8*, i8** %3
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 46
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %4, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %34, label %11
11: ; preds = %7, %1
%12 = tail call i64 @strlen(i8* %4)
%13 = load i8, i8* %0
%14 = icmp eq i8 %13, 0
br i1 %14, label %32, label %15
15: ; preds = %11
%16 = add i64 %12, -1
br label %17
17: ; preds = %15, %26
%18 = phi i8* [ %0, %15 ], [ %28, %26 ]
%19 = phi i8* [ %0, %15 ], [ %29, %26 ]
%20 = tail call i64 @strncmp(i8* %19, i8* %4, i64 %12)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
store i8 46, i8* %18
%23 = getelementptr inbounds i8, i8* %19, i64 %16
br label %26
24: ; preds = %17
%25 = load i8, i8* %19
store i8 %25, i8* %18
br label %26
26: ; preds = %22, %24
%27 = phi i8* [ %23, %22 ], [ %19, %24 ]
%28 = getelementptr inbounds i8, i8* %18, i64 1
%29 = getelementptr inbounds i8, i8* %27, i64 1
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %17
32: ; preds = %26, %11
%33 = phi i8* [ %0, %11 ], [ %28, %26 ]
store i8 0, i8* %33
br label %34
34: ; preds = %32, %7
ret void
}