#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) {
  static char CLOCALE[] = "C";
  if (locale == 0)
    return CLOCALE;
  if (strcmp(locale, CLOCALE) && strcmp(locale, "POSIX") && locale[0])
    return 0;
  return CLOCALE;
}


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    0x2ef7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1196 <setlocale+0x86>
mov    -0x18(%rbp),%rdi
lea    0x2ee3(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     118b <setlocale+0x7b>
mov    -0x18(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     118b <setlocale+0x7b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118b <setlocale+0x7b>
movq   $0x0,-0x8(%rbp)
jmp    1196 <setlocale+0x86>
lea    0x2e96(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setlocale>:
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1151 <setlocale+0x41>
mov    %rsi,%rbx
lea    0x2f05(%rip),%r14
mov    %rsi,%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1158 <setlocale+0x48>
lea    0xec6(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1158 <setlocale+0x48>
cmpb   $0x0,(%rbx)
je     1158 <setlocale+0x48>
xor    %r14d,%r14d
jmp    1158 <setlocale+0x48>
lea    0x2ed0(%rip),%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@setlocale.CLOCALE = internal global [2 x i8] c"C\00"
@.str = [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 i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @setlocale.CLOCALE, i64 0, i64 0), i8** %3
br label %25
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @setlocale.CLOCALE, i64 0, i64 0))
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %13
%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 ne i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
store i8* null, i8** %3
br label %25
24: ; preds = %17, %13, %9
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @setlocale.CLOCALE, i64 0, i64 0), i8** %3
br label %25
25: ; preds = %24, %23, %8
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
@setlocale.CLOCALE = internal global [2 x i8] c"C\00"
@.str = [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 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @setlocale.CLOCALE, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10, %7, %4
br label %14
14: ; preds = %10, %2, %13
%15 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @setlocale.CLOCALE, i64 0, i64 0), %13 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @setlocale.CLOCALE, i64 0, i64 0), %2 ], [ null, %10 ]
ret i8* %15
}