#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 */
scalar_t__ strcmp(char const *, char *);
char *setlocale(int category, const char *locale) {
  (void)category;
  if (!locale) {
    return "C";
  } else if (!*locale) {
    return "C";
  } else if (strcmp(locale, "C") == 0 || strcmp(locale, "POSIX") == 0) {
    return "C";
  } else {
    return NULL;
  }
}


x86 assembly (clang, -O0):
<setlocale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    113a <setlocale+0x2a>
lea    0xecf(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a3 <setlocale+0x93>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1157 <setlocale+0x47>
lea    0xeb2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a3 <setlocale+0x93>
mov    -0x18(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     118b <setlocale+0x7b>
mov    -0x18(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    119b <setlocale+0x8b>
lea    0xe6e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a3 <setlocale+0x93>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setlocale>:
push   %r14
push   %rbx
push   %rax
lea    0xee5(%rip),%r14
test   %rsi,%rsi
je     115f <setlocale+0x4f>
mov    %rsi,%rbx
cmpb   $0x0,(%rsi)
je     115f <setlocale+0x4f>
lea    0xed1(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     115f <setlocale+0x4f>
lea    0xebc(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
xor    %r14d,%r14d
test   %rax,%rax
lea    0xea5(%rip),%rax
cmove  %rax,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"C\00"
@.str.1 = [6 x i8] c"POSIX\00"
define i8* @setlocale(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%6 = load i32, i32* %4
%7 = load i8*, i8** %5
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3
br label %25
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %10
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3
br label %25
15: ; preds = %10
%16 = load i8*, i8** %5
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19, %15
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3
br label %25
24: ; preds = %19
store i8* null, i8** %3
br label %25
25: ; preds = %24, %23, %14, %9
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"C\00"
@.str.1 = [6 x i8] c"POSIX\00"
define i8* @setlocale(i32 %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* null
br label %14
14: ; preds = %10, %7, %4, %2
%15 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %7 ], [ %13, %10 ]
ret i8* %15
}