#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 /*<<< orphan*/ LC_CTYPE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int set_dos_codepage(int codepage) {
  static int initialized = -1;
  if (initialized < 0) {
    setlocale(LC_CTYPE, "");
    if (codepage < 0)
      codepage = 850;
    initialized = (codepage == 850) ? 1 : 0;
    if (!initialized)
      fprintf(stderr,
              "Cannot initialize unsupported codepage %d, only codepage 850 is "
              "supported\n",
              codepage);
  }
  return initialized;
}


x86 assembly (clang, -O0):
<set_dos_codepage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,0x2efe(%rip)
jge    11a1 <set_dos_codepage+0x81>
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
lea    0xf02(%rip),%rsi
call   1040 <setlocale@plt>
cmpl   $0x0,-0x4(%rbp)
jge    115e <set_dos_codepage+0x3e>
movl   $0x352,-0x4(%rbp)
mov    -0x4(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x352,%edx
cmove  %ecx,%eax
mov    %eax,0x2eb9(%rip)
cmpl   $0x0,0x2eb2(%rip)
jne    119c <set_dos_codepage+0x7c>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe69(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11a1 <set_dos_codepage+0x81>
mov    0x2e89(%rip),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_dos_codepage>:
push   %rbx
mov    0x2f09(%rip),%eax
test   %eax,%eax
js     112d <set_dos_codepage+0xd>
pop    %rbx
ret
mov    %edi,%ebx
mov    0x2eb2(%rip),%rax
mov    (%rax),%edi
lea    0xf0b(%rip),%rsi
call   1040 <setlocale@plt>
test   %ebx,%ebx
sets   %al
cmp    $0x352,%ebx
sete   %cl
or     %al,%cl
movzbl %cl,%ecx
mov    %ecx,0x2ed3(%rip)
mov    $0x1,%eax
test   %cl,%cl
jne    112b <set_dos_codepage+0xb>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
mov    %ebx,%edx
call   1030 <fprintf@plt>
mov    0x2ead(%rip),%eax
pop    %rbx
ret

LLVM IR (-O0):
@set_dos_codepage.initialized = internal global i32 -1
@LC_CTYPE = global i32 0
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [75 x i8] c"Cannot initialize unsupported codepage %d, only codepage 850 is supported\0A\00"
define i32 @set_dos_codepage(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* @set_dos_codepage.initialized
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %23
5: ; preds = %1
%6 = load i32, i32* @LC_CTYPE
%7 = call i32 @setlocale(i32 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %5
store i32 850, i32* %2
br label %11
11: ; preds = %10, %5
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, 850
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 1, i32 0
store i32 %15, i32* @set_dos_codepage.initialized
%16 = load i32, i32* @set_dos_codepage.initialized
%17 = icmp ne i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = load i32, i32* %2
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %11
br label %23
23: ; preds = %22, %1
%24 = load i32, i32* @set_dos_codepage.initialized
ret i32 %24
}

LLVM IR (-O2):
@set_dos_codepage.initialized = internal unnamed_addr global i32 -1
@LC_CTYPE = global i32 0
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [75 x i8] c"Cannot initialize unsupported codepage %d, only codepage 850 is supported\0A\00"
define i32 @set_dos_codepage(i32 %0) {
%2 = load i32, i32* @set_dos_codepage.initialized
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = load i32, i32* @LC_CTYPE
%6 = tail call i32 @setlocale(i32 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = icmp slt i32 %0, 0
%8 = icmp eq i32 %0, 850
%9 = or i1 %7, %8
%10 = zext i1 %9 to i32
store i32 %10, i32* @set_dos_codepage.initialized
br i1 %9, label %15, label %11
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%14 = load i32, i32* @set_dos_codepage.initialized
br label %15
15: ; preds = %4, %11, %1
%16 = phi i32 [ 1, %4 ], [ %14, %11 ], [ %2, %1 ]
ret i32 %16
}