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

/* Variables and functions */
int LC_ALL;
int /*<<< orphan*/ freelocale(int /*<<< orphan*/);
int /*<<< orphan*/ isalpha(int);
int /*<<< orphan*/ newlocale(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ setlocale(int, char *);
int /*<<< orphan*/ uselocale(int /*<<< orphan*/);
int do_test(void) {
  __locale_t loc_new, loc_old;
  int first = !!isalpha(0xE4);
  setlocale(LC_ALL, "de_DE");
  int global_de = !!isalpha(0xE4);
  loc_new = newlocale(1 << LC_ALL, "C", 0);
  loc_old = uselocale(loc_new);
  int used_c = !!isalpha(0xE4);
  uselocale(loc_old);
  int used_global = !!isalpha(0xE4);
  printf("started %d, after setlocale %d\n", first, global_de);
  printf("after uselocale %d, after LC_GLOBAL_LOCALE %d\n", used_c,
         used_global);
  freelocale(loc_new);
  return !(used_c == first && used_global == global_de);
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0xe4,%edi
call   1070 <isalpha@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1080 <setlocale@plt>
mov    $0xe4,%edi
call   1070 <isalpha@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x10(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edi
shl    %cl,%edi
lea    0xe3a(%rip),%rsi
xor    %edx,%edx
call   1050 <newlocale@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <uselocale@plt>
mov    %eax,-0x8(%rbp)
mov    $0xe4,%edi
call   1070 <isalpha@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <uselocale@plt>
mov    $0xe4,%edi
call   1070 <isalpha@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xdda(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1030 <freelocale@plt>
mov    -0x14(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x19(%rbp)
jne    126a <do_test+0x10a>
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xe4,%edi
call   1070 <isalpha@plt>
xor    %r14d,%r14d
test   %eax,%eax
setne  %r14b
mov    0x2e5e(%rip),%rbx
mov    (%rbx),%edi
lea    0xe75(%rip),%rsi
call   1080 <setlocale@plt>
mov    $0xe4,%edi
call   1070 <isalpha@plt>
xor    %r12d,%r12d
test   %eax,%eax
setne  %r12b
mov    (%rbx),%cl
mov    $0x1,%edi
shl    %cl,%edi
lea    0xe53(%rip),%rsi
xor    %edx,%edx
call   1050 <newlocale@plt>
mov    %eax,%r15d
mov    %eax,%edi
call   1060 <uselocale@plt>
mov    %eax,%ebp
mov    $0xe4,%edi
call   1070 <isalpha@plt>
xor    %ebx,%ebx
test   %eax,%eax
setne  %bl
mov    %ebp,%edi
call   1060 <uselocale@plt>
mov    $0xe4,%edi
call   1070 <isalpha@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
lea    0xe11(%rip),%rdi
mov    %r14d,%esi
mov    %r12d,%edx
call   1040 <printf@plt>
lea    0xe1f(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1040 <printf@plt>
mov    %r15d,%edi
call   1030 <freelocale@plt>
xor    %r14b,%bl
xor    %r12b,%bpl
or     %bl,%bpl
movzbl %bpl,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [6 x i8] c"de_DE\00"
@.str.1 = [2 x i8] c"C\00"
@.str.2 = [32 x i8] c"started %d, after setlocale %d\0A\00"
@.str.3 = [47 x i8] c"after uselocale %d, after LC_GLOBAL_LOCALE %d\0A\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = call i32 @isalpha(i32 228)
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
%10 = xor i1 %9, true
%11 = zext i1 %10 to i32
store i32 %11, i32* %3
%12 = load i32, i32* @LC_ALL
%13 = call i32 @setlocale(i32 %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @isalpha(i32 228)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
%17 = xor i1 %16, true
%18 = zext i1 %17 to i32
store i32 %18, i32* %4
%19 = load i32, i32* @LC_ALL
%20 = shl i32 1, %19
%21 = call i32 @newlocale(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32 %21, i32* %1
%22 = load i32, i32* %1
%23 = call i32 @uselocale(i32 %22)
store i32 %23, i32* %2
%24 = call i32 @isalpha(i32 228)
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
%27 = xor i1 %26, true
%28 = zext i1 %27 to i32
store i32 %28, i32* %5
%29 = load i32, i32* %2
%30 = call i32 @uselocale(i32 %29)
%31 = call i32 @isalpha(i32 228)
%32 = icmp ne i32 %31, 0
%33 = xor i1 %32, true
%34 = xor i1 %33, true
%35 = zext i1 %34 to i32
store i32 %35, i32* %6
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %37)
%39 = load i32, i32* %5
%40 = load i32, i32* %6
%41 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %39, i32 %40)
%42 = load i32, i32* %1
%43 = call i32 @freelocale(i32 %42)
%44 = load i32, i32* %5
%45 = load i32, i32* %3
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %51
47: ; preds = %0
%48 = load i32, i32* %6
%49 = load i32, i32* %4
%50 = icmp eq i32 %48, %49
br label %51
51: ; preds = %47, %0
%52 = phi i1 [ false, %0 ], [ %50, %47 ]
%53 = xor i1 %52, true
%54 = zext i1 %53 to i32
ret i32 %54
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [6 x i8] c"de_DE\00"
@.str.1 = [2 x i8] c"C\00"
@.str.2 = [32 x i8] c"started %d, after setlocale %d\0A\00"
@.str.3 = [47 x i8] c"after uselocale %d, after LC_GLOBAL_LOCALE %d\0A\00"
define i32 @do_test() {
%1 = tail call i32 @isalpha(i32 228)
%2 = icmp ne i32 %1, 0
%3 = zext i1 %2 to i32
%4 = load i32, i32* @LC_ALL
%5 = tail call i32 @setlocale(i32 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @isalpha(i32 228)
%7 = icmp ne i32 %6, 0
%8 = zext i1 %7 to i32
%9 = load i32, i32* @LC_ALL
%10 = shl nuw i32 1, %9
%11 = tail call i32 @newlocale(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 0)
%12 = tail call i32 @uselocale(i32 %11)
%13 = tail call i32 @isalpha(i32 228)
%14 = icmp ne i32 %13, 0
%15 = zext i1 %14 to i32
%16 = tail call i32 @uselocale(i32 %12)
%17 = tail call i32 @isalpha(i32 228)
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i32
%20 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %3, i32 %8)
%21 = tail call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %15, i32 %19)
%22 = tail call i32 @freelocale(i32 %11)
%23 = xor i1 %2, %14
%24 = xor i1 %7, %18
%25 = select i1 %23, i1 true, i1 %24
%26 = zext i1 %25 to i32
ret i32 %26
}