#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 /*<<< orphan*/ EXIT_FAILURE;
int LC_ALL;
int do_test(int /*<<< orphan*/ *);
int /*<<< orphan*/ *duplocale(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ freelocale(int /*<<< orphan*/ *);
int /*<<< orphan*/ *newlocale(int, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int main(void) {
  locale_t l;
  locale_t l2;
  int result;
  l = newlocale(1 << LC_ALL, "de_DE.ISO-8859-1", NULL);
  if (l == NULL) {
    printf("newlocale failed: %m\n");
    exit(EXIT_FAILURE);
  }
  puts("Running tests of created locale");
  result = do_test(l);
  l2 = duplocale(l);
  if (l2 == NULL) {
    printf("duplocale failed: %m\n");
    exit(EXIT_FAILURE);
  }
  freelocale(l);
  puts("Running tests of duplicated locale");
  result |= do_test(l2);
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edi
shl    %cl,%edi
lea    0xe6a(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <newlocale@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c8 <main+0x58>
lea    0xe5c(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1080 <do_test@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <duplocale@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1212 <main+0xa2>
lea    0xe48(%rip),%rdi
call   1050 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1040 <freelocale@plt>
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1080 <do_test@plt>
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e5d(%rip),%rax
mov    (%rax),%cl
mov    $0x1,%edi
shl    %cl,%edi
lea    0xe75(%rip),%rsi
xor    %edx,%edx
call   1060 <newlocale@plt>
test   %rax,%rax
je     11e5 <main+0x75>
mov    %rax,%rbx
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1080 <do_test@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1070 <duplocale@plt>
test   %rax,%rax
je     11ee <main+0x7e>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <freelocale@plt>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1080 <do_test@plt>
or     %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe25(%rip),%rdi
jmp    11f5 <main+0x85>
lea    0xe52(%rip),%rdi
call   1050 <printf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [17 x i8] c"de_DE.ISO-8859-1\00"
@.str.1 = [22 x i8] c"newlocale failed: %m\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [32 x i8] c"Running tests of created locale\00"
@.str.3 = [22 x i8] c"duplocale failed: %m\0A\00"
@.str.4 = [35 x i8] c"Running tests of duplicated locale\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @LC_ALL
%6 = shl i32 1, %5
%7 = call i32* @newlocale(i32 %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* null)
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = call i32 @puts(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32*, i32** %2
%17 = call i32 @do_test(i32* %16)
store i32 %17, i32* %4
%18 = load i32*, i32** %2
%19 = call i32* @duplocale(i32* %18)
store i32* %19, i32** %3
%20 = load i32*, i32** %3
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %14
%23 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %14
%27 = load i32*, i32** %2
%28 = call i32 @freelocale(i32* %27)
%29 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%30 = load i32*, i32** %3
%31 = call i32 @do_test(i32* %30)
%32 = load i32, i32* %4
%33 = or i32 %32, %31
store i32 %33, i32* %4
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [17 x i8] c"de_DE.ISO-8859-1\00"
@.str.1 = [22 x i8] c"newlocale failed: %m\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [32 x i8] c"Running tests of created locale\00"
@.str.3 = [22 x i8] c"duplocale failed: %m\0A\00"
@.str.4 = [35 x i8] c"Running tests of duplicated locale\00"
define i32 @main() {
%1 = load i32, i32* @LC_ALL
%2 = shl nuw i32 1, %1
%3 = tail call i32* @newlocale(i32 %2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* null)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @do_test(i32* %3)
%12 = tail call i32* @duplocale(i32* %3)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %9
%19 = tail call i32 @freelocale(i32* %3)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%21 = tail call i32 @do_test(i32* %12)
%22 = or i32 %21, %11
ret i32 %22
}