#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*/ LC_NUMERIC;
int /*<<< orphan*/ printf(char *, char *, ...);
char *setlocale(int /*<<< orphan*/, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(void) {
  char q[30];
  char *s;
  setlocale(LC_ALL, "");
  printf("after setlocale (LC_ALL, \"\"): %s\n", setlocale(LC_NUMERIC, NULL));
  strcpy(q, "de_DE.UTF-8");
  setlocale(LC_NUMERIC, q);
  printf("after setlocale (LC_NUMERIC, \"%s\"): %s\n", q,
         setlocale(LC_NUMERIC, NULL));
  strcpy(q, "de_DE.ISO-8859-1");
  s = setlocale(LC_NUMERIC, NULL);
  printf("after overwriting string: %s\n", s);
  return strcmp(s, "de_DE.UTF-8") != 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xec2(%rip),%rsi
call   1060 <setlocale@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <setlocale@plt>
mov    %rax,%rsi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1060 <setlocale@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <setlocale@plt>
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <setlocale@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe07(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    0xec8(%rip),%rsi
call   1060 <setlocale@plt>
mov    0x2e83(%rip),%r15
mov    (%r15),%edi
xor    %esi,%esi
call   1060 <setlocale@plt>
lea    0xe8a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9b(%rip),%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    (%r15),%edi
mov    %rbx,%rsi
call   1060 <setlocale@plt>
mov    (%r15),%edi
xor    %esi,%esi
call   1060 <setlocale@plt>
lea    0xe7d(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe91(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    (%r15),%edi
xor    %esi,%esi
call   1060 <setlocale@plt>
mov    %rax,%rbx
lea    0xe86(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
mov    %ecx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [34 x i8] c"after setlocale (LC_ALL, \22\22): %s\0A\00"
@LC_NUMERIC = global i32 0
@.str.2 = [12 x i8] c"de_DE.UTF-8\00"
@.str.3 = [40 x i8] c"after setlocale (LC_NUMERIC, \22%s\22): %s\0A\00"
@.str.4 = [17 x i8] c"de_DE.ISO-8859-1\00"
@.str.5 = [30 x i8] c"after overwriting string: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca i8*
store i32 0, i32* %1
%4 = load i32, i32* @LC_ALL
%5 = call i8* @setlocale(i32 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @LC_NUMERIC
%7 = call i8* @setlocale(i32 %6, i8* null)
%8 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @LC_NUMERIC
%12 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%13 = call i8* @setlocale(i32 %11, i8* %12)
%14 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%15 = load i32, i32* @LC_NUMERIC
%16 = call i8* @setlocale(i32 %15, i8* null)
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %14, i8* %16)
%18 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%20 = load i32, i32* @LC_NUMERIC
%21 = call i8* @setlocale(i32 %20, i8* null)
store i8* %21, i8** %3
%22 = load i8*, i8** %3
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %3
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
%27 = zext i1 %26 to i32
ret i32 %27
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [34 x i8] c"after setlocale (LC_ALL, \22\22): %s\0A\00"
@LC_NUMERIC = global i32 0
@.str.2 = [12 x i8] c"de_DE.UTF-8\00"
@.str.3 = [40 x i8] c"after setlocale (LC_NUMERIC, \22%s\22): %s\0A\00"
@.str.4 = [17 x i8] c"de_DE.ISO-8859-1\00"
@.str.5 = [30 x i8] c"after overwriting string: %s\0A\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @LC_ALL
%4 = tail call i8* @setlocale(i32 %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @LC_NUMERIC
%6 = tail call i8* @setlocale(i32 %5, i8* null)
%7 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @LC_NUMERIC
%10 = call i8* @setlocale(i32 %9, i8* %2)
%11 = load i32, i32* @LC_NUMERIC
%12 = call i8* @setlocale(i32 %11, i8* null)
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %2, i8* %12)
%14 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%15 = load i32, i32* @LC_NUMERIC
%16 = call i8* @setlocale(i32 %15, i8* null)
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %16)
%18 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
%20 = zext i1 %19 to i32
ret i32 %20
}