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

/* Variables and functions */
int /*<<< orphan*/ LC_NUMERIC;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, double);
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  char buffer[100];
  setlocale(LC_NUMERIC, "en_US");
  snprintf(buffer, 100, "%'d", 100000);
  if (strcmp(buffer, "100,000")) {
    printf("Expected '0.001,01' but got %s\n", buffer);
  }
  snprintf(buffer, 100, "%'f", 0.00101);
  if (strcmp(buffer, "0.001,01")) {
    printf("Expected '0.001,01' but got %s\n", buffer);
  }
  snprintf(buffer, 100, "%'g", 0.000001);
  if (strcmp(buffer, "0.001,001")) {
    printf("Expected '0.001,001' but got %s\n", buffer);
  }
  snprintf(buffer, 100, "%'g", 0.00000001);
  if (strcmp(buffer, "0.001,000,01")) {
    printf("Expected '0.001,000,01' but got %s\n", buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    0xeb7(%rip),%rsi
call   1060 <setlocale@plt>
lea    -0x80(%rbp),%rdi
mov    $0x64,%esi
lea    0xea8(%rip),%rdx
movsd  0xe7a(%rip),%xmm0
call   1040 <snprintf@plt>
lea    -0x80(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11b5 <main+0x75>
lea    -0x80(%rbp),%rsi
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    $0x64,%esi
lea    0xe8d(%rip),%rdx
movsd  0xe3b(%rip),%xmm0
call   1040 <snprintf@plt>
lea    -0x80(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11fc <main+0xbc>
lea    -0x80(%rbp),%rsi
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    $0x64,%esi
lea    0xe53(%rip),%rdx
movsd  0xdfc(%rip),%xmm0
call   1040 <snprintf@plt>
lea    -0x80(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1243 <main+0x103>
lea    -0x80(%rbp),%rsi
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    $0x64,%esi
lea    0xe0c(%rip),%rdx
movsd  0xdbd(%rip),%xmm0
call   1040 <snprintf@plt>
lea    -0x80(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     128a <main+0x14a>
lea    -0x80(%rbp),%rsi
lea    0xe16(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
lea    0xecb(%rip),%rsi
call   1060 <setlocale@plt>
lea    0xec5(%rip),%rdx
mov    %rsp,%rbx
movsd  0xe94(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x64,%esi
call   1040 <snprintf@plt>
lea    0xeaa(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     119c <main+0x5c>
lea    0xe9e(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
lea    0xeaf(%rip),%rdx
mov    %rsp,%rbx
movsd  0xe5a(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x64,%esi
call   1040 <snprintf@plt>
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11de <main+0x9e>
lea    0xe5c(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
lea    0xe7a(%rip),%rdx
mov    %rsp,%rbx
movsd  0xe20(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x64,%esi
call   1040 <snprintf@plt>
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1220 <main+0xe0>
lea    0xe55(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
lea    0xe38(%rip),%rdx
mov    %rsp,%rbx
movsd  0xde6(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x64,%esi
call   1040 <snprintf@plt>
lea    0xe48(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1262 <main+0x122>
lea    0xe41(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@LC_NUMERIC = global i32 0
@.str = [6 x i8] c"en_US\00"
@.str.1 = [4 x i8] c"%'d\00"
@.str.2 = [8 x i8] c"100,000\00"
@.str.3 = [32 x i8] c"Expected '0.001,01' but got %s\0A\00"
@.str.4 = [4 x i8] c"%'f\00"
@.str.5 = [9 x i8] c"0.001,01\00"
@.str.6 = [4 x i8] c"%'g\00"
@.str.7 = [10 x i8] c"0.001,001\00"
@.str.8 = [33 x i8] c"Expected '0.001,001' but got %s\0A\00"
@.str.9 = [13 x i8] c"0.001,000,01\00"
@.str.10 = [36 x i8] c"Expected '0.001,000,01' but got %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @LC_NUMERIC
%8 = call i32 @setlocale(i32 %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%10 = call i32 @snprintf(i8* %9, i32 100, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double 1.000000e+05)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%16 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14, %2
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%19 = call i32 @snprintf(i8* %18, i32 100, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double 1.010000e-03)
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %23, %17
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%28 = call i32 @snprintf(i8* %27, i32 100, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double 0x3EB0C6F7A0B5ED8D)
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%34 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %32, %26
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%37 = call i32 @snprintf(i8* %36, i32 100, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double 1.000000e-08)
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%43 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %41, %35
ret i32 0
}

LLVM IR (-O2):
@LC_NUMERIC = global i32 0
@.str = [6 x i8] c"en_US\00"
@.str.1 = [4 x i8] c"%'d\00"
@.str.2 = [8 x i8] c"100,000\00"
@.str.3 = [32 x i8] c"Expected '0.001,01' but got %s\0A\00"
@.str.4 = [4 x i8] c"%'f\00"
@.str.5 = [9 x i8] c"0.001,01\00"
@.str.6 = [4 x i8] c"%'g\00"
@.str.7 = [10 x i8] c"0.001,001\00"
@.str.8 = [33 x i8] c"Expected '0.001,001' but got %s\0A\00"
@.str.9 = [13 x i8] c"0.001,000,01\00"
@.str.10 = [36 x i8] c"Expected '0.001,000,01' but got %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @LC_NUMERIC
%6 = tail call i32 @setlocale(i32 %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @snprintf(i8* %4, i32 100, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double 1.000000e+05)
%8 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %12
12: ; preds = %10, %2
%13 = call i32 @snprintf(i8* %4, i32 100, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double 1.010000e-03)
%14 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %18
18: ; preds = %16, %12
%19 = call i32 @snprintf(i8* %4, i32 100, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double 0x3EB0C6F7A0B5ED8D)
%20 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i8* %4)
br label %24
24: ; preds = %22, %18
%25 = call i32 @snprintf(i8* %4, i32 100, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), double 1.000000e-08)
%26 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i8* %4)
br label %30
30: ; preds = %28, %24
ret i32 0
}