#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_ALL;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *malloc(int);
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 = malloc(201);
  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, 200, 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    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xc9,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
movsd  %xmm0,-0x20(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1090 <setlocale@plt>
cmp    $0x0,%rax
jne    1211 <main+0x81>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdfe(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
movsd  -0x20(%rbp),%xmm0
mov    $0xc8,%esi
call   1050 <snprintf@plt>
cmp    $0xffffffff,%eax
jne    124b <main+0xbb>
lea    0xde1(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x3,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     12e2 <main+0x152>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
call   1060 <strcmp@plt>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    %rax,%rdi
lea    0xdac(%rip),%r9
lea    0xd9f(%rip),%rax
cmp    $0x0,%rdi
cmovne %rax,%r9
lea    0xd53(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    $0xc9,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    0x18(%rbx),%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
movsd  %xmm0,(%rsp)
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rsi
call   1090 <setlocale@plt>
test   %rax,%rax
je     1209 <main+0x79>
mov    0x10(%rbx),%rdx
mov    %r14,%rdi
mov    $0xc8,%esi
movsd  (%rsp),%xmm0
call   1050 <snprintf@plt>
cmp    $0xffffffff,%eax
je     122c <main+0x9c>
mov    0x20(%rbx),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1242 <main+0xb2>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xde3(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
lea    0xdea(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x3,%edi
call   10b0 <exit@plt>
mov    0x8(%rbx),%r15
mov    0x10(%rbx),%r12
mov    0x20(%rbx),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
lea    0xe06(%rip),%rax
lea    0xdf9(%rip),%r9
cmove  %rax,%r9
lea    0xdb1(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %r14,%r8
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <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 i8*
%7 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i8* @malloc(i32 201)
store i8* %8, i8** %6
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 3
%11 = load i8*, i8** %10
%12 = call double @strtod(i8* %11, i32* null)
store double %12, double* %7
%13 = load i32, i32* @LC_ALL
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @setlocale(i32 %13, i8* %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %26
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 2)
unreachable
26: ; preds = %2
%27 = load i8*, i8** %6
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = load double, double* %7
%32 = call i32 @snprintf(i8* %27, i32 200, i8* %30, double %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 3)
unreachable
37: ; preds = %26
%38 = load i8*, i8** %6
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 4
%41 = load i8*, i8** %40
%42 = call i64 @strcmp(i8* %38, i8* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %65
44: ; preds = %37
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 4
%53 = load i8*, i8** %52
%54 = load i8*, i8** %6
%55 = load i8*, i8** %6
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 4
%58 = load i8*, i8** %57
%59 = call i64 @strcmp(i8* %55, i8* %58)
%60 = icmp ne i64 %59, 0
%61 = zext i1 %60 to i64
%62 = select i1 %60, 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)
%63 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i8* %47, i8* %50, i8* %53, i8* %54, i8* %62)
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %37
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 = tail call dereferenceable_or_null(201) i8* @malloc(i32 201)
%4 = getelementptr inbounds i8*, i8** %1, i64 3
%5 = load i8*, i8** %4
%6 = tail call double @strtod(i8* nocapture %5, i32* null)
%7 = load i32, i32* @LC_ALL
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @setlocale(i32 %7, i8* %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %8
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 2)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 @snprintf(i8* %3, i32 200, i8* %19, double %6)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 3)
unreachable
25: ; preds = %17
%26 = getelementptr inbounds i8*, i8** %1, i64 4
%27 = load i8*, i8** %26
%28 = tail call i64 @strcmp(i8* %3, i8* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %39, label %30
30: ; preds = %25
%31 = load i8*, i8** %8
%32 = load i8*, i8** %18
%33 = load i8*, i8** %26
%34 = tail call i64 @strcmp(i8* %3, i8* %33)
%35 = icmp eq i64 %34, 0
%36 = select i1 %35, 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)
%37 = tail call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %32, i8* %33, i8* %3, i8* %36)
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %25
ret i32 0
}