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

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ *setlocale(int /*<<< orphan*/, char *);
int snprintf(char *, int, char *, double);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
double strtod(char *, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  char s[200];
  double val;
  val = strtod(argv[3], NULL);
  if (setlocale(LC_ALL, argv[1]) == NULL) {
    fprintf(stderr, "setlocale(LC_ALL, \"%s\"): %m\n", argv[1]);
    exit(2);
  }
  if (snprintf(s, sizeof(s), argv[2], val) == -1) {
    perror("snprintf");
    exit(3);
  }
  if (strcmp(s, argv[4]) != 0) {
    printf(
        "locale: \"%s\", format: \"%s\", expected: \"%s\", got: \"%s\" => %s\n",
        argv[1], argv[2], argv[4], s,
        strcmp(s, argv[4]) != 0 ? "false" : "correct");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
movsd  %xmm0,-0xe8(%rbp)
ff
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1080 <setlocale@plt>
cmp    $0x0,%rax
jne    11f9 <main+0x79>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe16(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    -0xe0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
movsd  -0xe8(%rbp),%xmm0
ff
mov    $0xc8,%esi
call   1050 <snprintf@plt>
cmp    $0xffffffff,%eax
jne    1239 <main+0xb9>
lea    0xdf3(%rip),%rdi
call   1090 <perror@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>
lea    -0xe0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     12f1 <main+0x171>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x108(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x100(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0xf8(%rbp)
lea    -0xe0(%rbp),%rax
mov    %rax,-0xf0(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
call   1060 <strcmp@plt>
mov    -0x108(%rbp),%rsi
mov    -0x100(%rbp),%rdx
mov    -0xf8(%rbp),%rcx
mov    -0xf0(%rbp),%r8
mov    %rax,%rdi
lea    0xd9d(%rip),%r9
lea    0xd90(%rip),%rax
cmp    $0x0,%rdi
cmovne %rax,%r9
lea    0xd44(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %rsi,%rbx
mov    0x18(%rsi),%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
movsd  %xmm0,0x8(%rsp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rsi
call   1080 <setlocale@plt>
test   %rax,%rax
je     11fb <main+0x7b>
mov    0x10(%rbx),%rdx
lea    0x10(%rsp),%rdi
mov    $0xc8,%esi
movsd  0x8(%rsp),%xmm0
call   1050 <snprintf@plt>
cmp    $0xffffffff,%eax
je     121e <main+0x9e>
mov    0x20(%rbx),%rsi
lea    0x10(%rsp),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1234 <main+0xb4>
xor    %eax,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdf1(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    0xdf8(%rip),%rdi
call   1090 <perror@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>
mov    0x8(%rbx),%r14
mov    0x10(%rbx),%r15
mov    0x20(%rbx),%rbx
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
lea    0xe0f(%rip),%rax
lea    0xe02(%rip),%r9
cmove  %rax,%r9
lea    0xdba(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %r12,%r8
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@LC_ALL = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"setlocale(LC_ALL, \22%s\22): %m\0A\00"
@.str.1 = [9 x i8] c"snprintf\00"
@.str.2 = [61 x i8] c"locale: \22%s\22, format: \22%s\22, expected: \22%s\22, got: \22%s\22 => %s\0A\00"
@.str.3 = [6 x i8] c"false\00"
@.str.4 = [8 x i8] c"correct\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [200 x i8]
%7 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 3
%10 = load i8*, i8** %9
%11 = call double @strtod(i8* %10, i32* null)
store double %11, double* %7
%12 = load i32, i32* @LC_ALL
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @setlocale(i32 %12, i8* %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 2)
unreachable
25: ; preds = %2
%26 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = load double, double* %7
%31 = call i32 @snprintf(i8* %26, i32 200, i8* %29, double %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 3)
unreachable
36: ; preds = %25
%37 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 4
%40 = load i8*, i8** %39
%41 = call i64 @strcmp(i8* %37, i8* %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %64
43: ; preds = %36
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 4
%52 = load i8*, i8** %51
%53 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%54 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 4
%57 = load i8*, i8** %56
%58 = call i64 @strcmp(i8* %54, i8* %57)
%59 = icmp ne i64 %58, 0
%60 = zext i1 %59 to i64
%61 = select i1 %59, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0)
%62 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i8* %46, i8* %49, i8* %52, i8* %53, i8* %61)
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %36
ret i32 0
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"setlocale(LC_ALL, \22%s\22): %m\0A\00"
@.str.1 = [9 x i8] c"snprintf\00"
@.str.2 = [61 x i8] c"locale: \22%s\22, format: \22%s\22, expected: \22%s\22, got: \22%s\22 => %s\0A\00"
@.str.3 = [6 x i8] c"false\00"
@.str.4 = [8 x i8] c"correct\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [200 x i8]
%4 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 3
%6 = load i8*, i8** %5
%7 = tail call double @strtod(i8* nocapture %6, i32* null)
%8 = load i32, i32* @LC_ALL
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @setlocale(i32 %8, i8* %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %9
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = tail call i32 @exit(i32 2)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @snprintf(i8* %4, i32 200, i8* %20, double %7)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 3)
unreachable
26: ; preds = %18
%27 = getelementptr inbounds i8*, i8** %1, i64 4
%28 = load i8*, i8** %27
%29 = call i64 @strcmp(i8* %4, i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %40, label %31
31: ; preds = %26
%32 = load i8*, i8** %9
%33 = load i8*, i8** %19
%34 = load i8*, i8** %27
%35 = call i64 @strcmp(i8* %4, i8* %34)
%36 = icmp eq i64 %35, 0
%37 = select i1 %36, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%38 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i8* %32, i8* %33, i8* %34, i8* %4, i8* %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %26
ret i32 0
}