#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 */
typedef int /*<<< orphan*/ dir;

/* Variables and functions */
int /*<<< orphan*/ Cvar_Get(char *, char *, int);
int /*<<< orphan*/ Cvar_VariableString(char *);
int /*<<< orphan*/ Cvar_VariableStringBuffer(char *, char *, int);
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ Q_strcat(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ bindtextdomain(char *, char *);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int /*<<< orphan*/ textdomain(char *);
void Sys_InitGettext(void) {
  char dir[2 * 256];
  Cvar_Get("localepath", "", 0x0001 | 0x0010);
  Cvar_Get("locale", "/locale", 0x0001 | 0x0010);
  Cvar_VariableStringBuffer("localepath", dir, sizeof(dir));
  if (!*dir)
    Cvar_VariableStringBuffer("fs_homepath", dir, 256);
  Q_strcat(dir, sizeof(dir), Cvar_VariableString("locale"));
  errno = 0;
  if (!setlocale(LC_ALL, "")) {
    fprintf(stderr, "Failed to set LC_ALL to native locale: %s\n",
            errno ? strerror(errno) : "Unknown error");
  }
  bindtextdomain("bb_demo", dir);
  textdomain("bb_demo");
}


x86 assembly (clang, -O0):
<Sys_InitGettext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
lea    0xe5e(%rip),%rdi
lea    0xea0(%rip),%rsi
mov    $0x11,%edx
call   10a0 <Cvar_Get@plt>
lea    0xe52(%rip),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x11,%edx
call   10a0 <Cvar_Get@plt>
lea    -0x200(%rbp),%rsi
lea    0xe27(%rip),%rdi
mov    $0x200,%edx
call   1080 <Cvar_VariableStringBuffer@plt>
cmpb   $0x0,-0x200(%rbp)
jne    1208 <Sys_InitGettext+0x78>
lea    -0x200(%rbp),%rsi
lea    0xe15(%rip),%rdi
mov    $0x100,%edx
call   1080 <Cvar_VariableStringBuffer@plt>
lea    -0x200(%rbp),%rax
mov    %rax,-0x208(%rbp)
lea    0xdef(%rip),%rdi
call   10b0 <Cvar_VariableString@plt>
mov    -0x208(%rbp),%rdi
mov    %eax,%edx
mov    $0x200,%esi
call   1070 <Q_strcat@plt>
mov    0x2d9c(%rip),%rax
movq   $0x0,(%rax)
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
call   1060 <setlocale@plt>
cmp    $0x0,%eax
jne    12c8 <Sys_InitGettext+0x138>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20c(%rbp)
mov    0x2d61(%rip),%rax
cmpq   $0x0,(%rax)
je     129c <Sys_InitGettext+0x10c>
mov    0x2d50(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %rax,-0x218(%rbp)
jmp    12af <Sys_InitGettext+0x11f>
lea    0xda7(%rip),%rax
mov    %rax,-0x218(%rbp)
jmp    12af <Sys_InitGettext+0x11f>
mov    -0x20c(%rbp),%edi
mov    -0x218(%rbp),%rdx
lea    0xd5c(%rip),%rsi
call   1050 <fprintf@plt>
lea    -0x200(%rbp),%rsi
lea    0xd82(%rip),%rdi
call   1040 <bindtextdomain@plt>
lea    0xd76(%rip),%rdi
call   1030 <textdomain@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Sys_InitGettext>:
push   %rbp
push   %rbx
sub    $0x208,%rsp
lea    0xe60(%rip),%rbx
lea    0xea2(%rip),%rsi
mov    %rbx,%rdi
mov    $0x11,%edx
call   10a0 <Cvar_Get@plt>
lea    0xe51(%rip),%rdi
lea    0xe49(%rip),%rsi
mov    $0x11,%edx
call   10a0 <Cvar_Get@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x200,%edx
call   1080 <Cvar_VariableStringBuffer@plt>
cmpb   $0x0,(%rsp)
jne    11f6 <Sys_InitGettext+0x66>
lea    0xe2a(%rip),%rdi
mov    %rsp,%rsi
mov    $0x100,%edx
call   1080 <Cvar_VariableStringBuffer@plt>
lea    0xe0f(%rip),%rdi
call   10b0 <Cvar_VariableString@plt>
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %eax,%edx
call   1070 <Q_strcat@plt>
mov    0x2dc0(%rip),%rbx
movq   $0x0,(%rbx)
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%rip),%rsi
call   1060 <setlocale@plt>
test   %eax,%eax
jne    1268 <Sys_InitGettext+0xd8>
mov    0x2da1(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rdi
test   %rdi,%rdi
je     1253 <Sys_InitGettext+0xc3>
call   1090 <strerror@plt>
mov    %rax,%rdx
jmp    125a <Sys_InitGettext+0xca>
lea    0xdf0(%rip),%rdx
lea    0xdbe(%rip),%rsi
mov    %ebp,%edi
call   1050 <fprintf@plt>
lea    0xde9(%rip),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1040 <bindtextdomain@plt>
mov    %rbx,%rdi
call   1030 <textdomain@plt>
add    $0x208,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"localepath\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [7 x i8] c"locale\00"
@.str.3 = [8 x i8] c"/locale\00"
@.str.4 = [12 x i8] c"fs_homepath\00"
@errno = global i64 0
@LC_ALL = global i32 0
@stderr = global i32 0
@.str.5 = [43 x i8] c"Failed to set LC_ALL to native locale: %s\0A\00"
@.str.6 = [14 x i8] c"Unknown error\00"
@.str.7 = [8 x i8] c"bb_demo\00"
define void @Sys_InitGettext() {
%1 = alloca [512 x i8]
%2 = call i32 @Cvar_Get(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i32 17)
%3 = call i32 @Cvar_Get(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 17)
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%5 = call i32 @Cvar_VariableStringBuffer(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %4, i32 512)
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %0
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%11 = call i32 @Cvar_VariableStringBuffer(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32 256)
br label %12
12: ; preds = %9, %0
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%14 = call i32 @Cvar_VariableString(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @Q_strcat(i8* %13, i32 512, i32 %14)
store i64 0, i64* @errno
%16 = load i32, i32* @LC_ALL
%17 = call i32 @setlocale(i32 %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp ne i32 %17, 0
br i1 %18, label %30, label %19
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = load i64, i64* @errno
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i64, i64* @errno
%25 = call i8* @strerror(i64 %24)
br label %27
26: ; preds = %19
br label %27
27: ; preds = %26, %23
%28 = phi i8* [ %25, %23 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), %26 ]
%29 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %12
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%32 = call i32 @bindtextdomain(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %31)
%33 = call i32 @textdomain(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"localepath\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [7 x i8] c"locale\00"
@.str.3 = [8 x i8] c"/locale\00"
@.str.4 = [12 x i8] c"fs_homepath\00"
@errno = global i64 0
@LC_ALL = global i32 0
@stderr = global i32 0
@.str.5 = [43 x i8] c"Failed to set LC_ALL to native locale: %s\0A\00"
@.str.6 = [14 x i8] c"Unknown error\00"
@.str.7 = [8 x i8] c"bb_demo\00"
define void @Sys_InitGettext() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @Cvar_Get(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i32 17)
%4 = tail call i32 @Cvar_Get(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 17)
%5 = call i32 @Cvar_VariableStringBuffer(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %2, i32 512)
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @Cvar_VariableStringBuffer(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %2, i32 256)
br label %10
10: ; preds = %8, %0
%11 = call i32 @Cvar_VariableString(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @Q_strcat(i8* %2, i32 512, i32 %11)
store i64 0, i64* @errno
%13 = load i32, i32* @LC_ALL
%14 = call i32 @setlocale(i32 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = load i64, i64* @errno
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = call i8* @strerror(i64 %18)
br label %22
22: ; preds = %16, %20
%23 = phi i8* [ %21, %20 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), %16 ]
%24 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %10
%26 = call i32 @bindtextdomain(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %2)
%27 = call i32 @textdomain(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
ret void
}