#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 */
char *getenv(char *);
scalar_t__ strncmp(char *, char *, int);
int japanese_locale(void) {
  char *lang;
  lang = getenv("LC_MESSAGE");
  if (lang) {
    if ((strncmp(lang, "ja", 2) == 0))
      return 0;
    return 1;
  }
  lang = getenv("LANG");
  if (lang && (strncmp(lang, "ja", 2) == 0))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<japanese_locale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117a <japanese_locale+0x5a>
mov    -0x10(%rbp),%rdi
lea    0xebd(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    116e <japanese_locale+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    11c7 <japanese_locale+0xa7>
movl   $0x1,-0x4(%rbp)
jmp    11c7 <japanese_locale+0xa7>
lea    0xe8d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c0 <japanese_locale+0xa0>
mov    -0x10(%rbp),%rdi
lea    0xe6b(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    11c0 <japanese_locale+0xa0>
movl   $0x0,-0x4(%rbp)
jmp    11c7 <japanese_locale+0xa7>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<japanese_locale>:
push   %rax
lea    0xed8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1153 <japanese_locale+0x33>
lea    0xed2(%rip),%rsi
mov    %rax,%rdi
mov    $0x2,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
pop    %rcx
ret
lea    0xeb4(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     117d <japanese_locale+0x5d>
lea    0xea0(%rip),%rsi
mov    %rax,%rdi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1184 <japanese_locale+0x64>
mov    $0x1,%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"LC_MESSAGE\00"
@.str.1 = [3 x i8] c"ja\00"
@.str.2 = [5 x i8] c"LANG\00"
define i32 @japanese_locale() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %7, label %3
3: ; preds = %0
%4 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%5 = icmp ne i64 %4, 0
%6 = zext i1 %5 to i32
br label %14
7: ; preds = %0
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %10, %7
br label %14
14: ; preds = %10, %3, %13
%15 = phi i32 [ 1, %13 ], [ %6, %3 ], [ 0, %10 ]
ret i32 %15
}