#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*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
char *setlocale(int /*<<< orphan*/, char *);
char *strdup(char *);
int main(int argc, char **argv) {
  char *oldlocale, *savedlocale, *result;
  setlocale(LC_ALL, "");
  printf("Setting locale to 'C'\n");
  oldlocale = setlocale(LC_ALL, NULL);
  savedlocale = strdup(oldlocale);
  printf("Old locale setting: %s\n", oldlocale);
  result = setlocale(LC_ALL, "C");
  printf("Result of setlocale: %s\n", result);
  printf("Old locale setting: %s\n", oldlocale);
  setlocale(LC_ALL, savedlocale);
  free(savedlocale);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    0xeb0(%rip),%rsi
call   1050 <setlocale@plt>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <setlocale@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
call   1050 <setlocale@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
call   1050 <setlocale@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e81(%rip),%r12
mov    (%r12),%edi
lea    0xec8(%rip),%rsi
call   1060 <setlocale@plt>
lea    0xebd(%rip),%rdi
call   1040 <puts@plt>
mov    (%r12),%edi
xor    %esi,%esi
call   1060 <setlocale@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <strdup@plt>
mov    %rax,%r14
lea    0xe65(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r12),%edi
lea    0xe65(%rip),%rsi
call   1060 <setlocale@plt>
lea    0xe5b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r12),%edi
mov    %r14,%rsi
call   1060 <setlocale@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [23 x i8] c"Setting locale to 'C'\0A\00"
@.str.2 = [24 x i8] c"Old locale setting: %s\0A\00"
@.str.3 = [2 x i8] c"C\00"
@.str.4 = [25 x i8] c"Result of setlocale: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @LC_ALL
%10 = call i8* @setlocale(i32 %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @LC_ALL
%13 = call i8* @setlocale(i32 %12, i8* null)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = call i8* @strdup(i8* %14)
store i8* %15, i8** %7
%16 = load i8*, i8** %6
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @LC_ALL
%19 = call i8* @setlocale(i32 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @LC_ALL
%25 = load i8*, i8** %7
%26 = call i8* @setlocale(i32 %24, i8* %25)
%27 = load i8*, i8** %7
%28 = call i32 @free(i8* %27)
ret i32 0
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.2 = [24 x i8] c"Old locale setting: %s\0A\00"
@.str.3 = [2 x i8] c"C\00"
@.str.4 = [25 x i8] c"Result of setlocale: %s\0A\00"
@str = [22 x i8] c"Setting locale to 'C'\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%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 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* @LC_ALL
%7 = tail call i8* @setlocale(i32 %6, i8* null)
%8 = tail call i8* @strdup(i8* %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%10 = load i32, i32* @LC_ALL
%11 = tail call i8* @setlocale(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%14 = load i32, i32* @LC_ALL
%15 = tail call i8* @setlocale(i32 %14, i8* %8)
%16 = tail call i32 @free(i8* %8)
ret i32 0
}