#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 LC_ALL;
int LC_TIME;
char *setlocale(int category, const char *locale) {
  if (category > LC_TIME || category < LC_ALL)
    return NULL;
  if (!locale || locale[0] == '\0' || locale[0] == 'C' && locale[1] == '\0') {
    return "C";
  }
  return NULL;
}


x86 assembly (clang, -O0):
<setlocale>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2ed3(%rip),%rcx
cmp    (%rcx),%eax
jg     112f <setlocale+0x2f>
mov    -0xc(%rbp),%eax
mov    0x2eb1(%rip),%rcx
cmp    (%rcx),%eax
jge    113c <setlocale+0x3c>
movq   $0x0,-0x8(%rbp)
jmp    1190 <setlocale+0x90>
cmpq   $0x0,-0x18(%rbp)
je     1178 <setlocale+0x78>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1178 <setlocale+0x78>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x43,%eax
jne    1188 <setlocale+0x88>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1188 <setlocale+0x88>
lea    0xe81(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1190 <setlocale+0x90>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<setlocale>:
mov    0x2ee1(%rip),%rcx
xor    %eax,%eax
cmp    %edi,(%rcx)
jl     1137 <setlocale+0x37>
mov    0x2ec4(%rip),%rcx
cmp    %edi,(%rcx)
jg     1137 <setlocale+0x37>
lea    0xee1(%rip),%rax
test   %rsi,%rsi
je     1137 <setlocale+0x37>
mov    (%rsi),%cl
test   %cl,%cl
je     1137 <setlocale+0x37>
cmp    $0x43,%cl
jne    1135 <setlocale+0x35>
cmpb   $0x0,0x1(%rsi)
je     1137 <setlocale+0x37>
xor    %eax,%eax
ret

LLVM IR (-O0):
@LC_TIME = global i32 0
@LC_ALL = global i32 0
@.str = [2 x i8] c"C\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 i32, i32* @LC_TIME
%8 = icmp sgt i32 %6, %7
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* %4
%11 = load i32, i32* @LC_ALL
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %9, %2
store i8* null, i8** %3
br label %37
14: ; preds = %9
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %35
17: ; preds = %14
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 0
br i1 %22, label %35, label %23
23: ; preds = %17
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 67
br i1 %28, label %29, label %36
29: ; preds = %23
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29, %17, %14
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3
br label %37
36: ; preds = %29, %23
store i8* null, i8** %3
br label %37
37: ; preds = %36, %35, %13
%38 = load i8*, i8** %3
ret i8* %38
}

LLVM IR (-O2):
@LC_TIME = global i32 0
@LC_ALL = global i32 0
@.str = [2 x i8] c"C\00"
define i8* @setlocale(i32 %0, i8* %1) {
%3 = load i32, i32* @LC_TIME
%4 = icmp slt i32 %3, %0
%5 = load i32, i32* @LC_ALL
%6 = icmp sgt i32 %5, %0
%7 = select i1 %4, i1 true, i1 %6
br i1 %7, label %17, label %8
8: ; preds = %2
%9 = icmp eq i8* %1, null
br i1 %9, label %17, label %10
10: ; preds = %8
%11 = load i8, i8* %1
switch i8 %11, label %16 [
i8 0, label %17
i8 67, label %12
]
12: ; preds = %10
%13 = getelementptr inbounds i8, i8* %1, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %10, %12
br label %17
17: ; preds = %8, %12, %10, %2, %16
%18 = phi i8* [ null, %16 ], [ null, %2 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %10 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %12 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %8 ]
ret i8* %18
}