#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 scalar_t__ nl_catd;

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ LC_MESSAGES;
int /*<<< orphan*/ NL_CAT_LOCALE;
int /*<<< orphan*/ catclose(scalar_t__);
char *catgets(scalar_t__, int, int, char *);
scalar_t__ catopen(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
char *setlocale(int /*<<< orphan*/, char *);
int main(void) {
  nl_catd catalog;
  setlocale(LC_ALL, "");
  printf("LC_MESSAGES = %s\n", setlocale(LC_MESSAGES, NULL));
  catalog = catopen("sample", NL_CAT_LOCALE);
  if (catalog == (nl_catd)-1) {
    printf("no catalog: %m\n");
    exit(1);
  }
  printf("%s\n", catgets(catalog, 1, 1, "sample 1"));
  printf("%s\n", catgets(catalog, 1, 2, "sample 2"));
  printf("%s\n", catgets(catalog, 1, 3, "sample 3"));
  printf("%s\n", catgets(catalog, 1, 4, "sample 4"));
  printf("%s\n", catgets(catalog, 1, 5, "sample 5"));
  printf("%s\n", catgets(catalog, 1, 6, "sample 6"));
  printf("%s\n", catgets(catalog, 1, 7, "sample 7"));
  catclose(catalog);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
call   1050 <setlocale@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <setlocale@plt>
mov    %rax,%rsi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
lea    0xe5b(%rip),%rdi
call   1040 <catopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0xffffffffffffffff,-0x10(%rbp)
jne    11e3 <main+0x83>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%edx
lea    0xe36(%rip),%rcx
mov    %edx,%esi
call   1070 <catgets@plt>
mov    %rax,%rsi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
lea    0xe12(%rip),%rcx
call   1070 <catgets@plt>
mov    %rax,%rsi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
mov    $0x3,%edx
lea    0xdf0(%rip),%rcx
call   1070 <catgets@plt>
mov    %rax,%rsi
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
lea    0xdce(%rip),%rcx
call   1070 <catgets@plt>
mov    %rax,%rsi
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
mov    $0x5,%edx
lea    0xdac(%rip),%rcx
call   1070 <catgets@plt>
mov    %rax,%rsi
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
mov    $0x6,%edx
lea    0xd8a(%rip),%rcx
call   1070 <catgets@plt>
mov    %rax,%rsi
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
mov    $0x7,%edx
lea    0xd68(%rip),%rcx
call   1070 <catgets@plt>
mov    %rax,%rsi
lea    0xd08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <catclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xea7(%rip),%rsi
call   1060 <setlocale@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1060 <setlocale@plt>
lea    0xe63(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
lea    0xe5b(%rip),%rdi
call   1050 <catopen@plt>
cmp    $0xffffffffffffffff,%rax
je     12bc <main+0x14c>
mov    %rax,%rbx
lea    0xe59(%rip),%rcx
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1080 <catgets@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
lea    0xe41(%rip),%rcx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
call   1080 <catgets@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
lea    0xe29(%rip),%rcx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
call   1080 <catgets@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
lea    0xe11(%rip),%rcx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1080 <catgets@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
lea    0xdf9(%rip),%rcx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1080 <catgets@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
lea    0xde1(%rip),%rcx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x6,%edx
call   1080 <catgets@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
lea    0xdc9(%rip),%rcx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x7,%edx
call   1080 <catgets@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1070 <catclose@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xd56(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [18 x i8] c"LC_MESSAGES = %s\0A\00"
@LC_MESSAGES = global i32 0
@.str.2 = [7 x i8] c"sample\00"
@NL_CAT_LOCALE = global i32 0
@.str.3 = [16 x i8] c"no catalog: %m\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [9 x i8] c"sample 1\00"
@.str.6 = [9 x i8] c"sample 2\00"
@.str.7 = [9 x i8] c"sample 3\00"
@.str.8 = [9 x i8] c"sample 4\00"
@.str.9 = [9 x i8] c"sample 5\00"
@.str.10 = [9 x i8] c"sample 6\00"
@.str.11 = [9 x i8] c"sample 7\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = load i32, i32* @LC_ALL
%4 = call i8* @setlocale(i32 %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @LC_MESSAGES
%6 = call i8* @setlocale(i32 %5, i8* null)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @NL_CAT_LOCALE
%9 = call i64 @catopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %8)
store i64 %9, i64* %2
%10 = load i64, i64* %2
%11 = icmp eq i64 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = load i64, i64* %2
%17 = call i8* @catgets(i64 %16, i32 1, i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %17)
%19 = load i64, i64* %2
%20 = call i8* @catgets(i64 %19, i32 1, i32 2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %20)
%22 = load i64, i64* %2
%23 = call i8* @catgets(i64 %22, i32 1, i32 3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = load i64, i64* %2
%26 = call i8* @catgets(i64 %25, i32 1, i32 4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = load i64, i64* %2
%29 = call i8* @catgets(i64 %28, i32 1, i32 5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%31 = load i64, i64* %2
%32 = call i8* @catgets(i64 %31, i32 1, i32 6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %32)
%34 = load i64, i64* %2
%35 = call i8* @catgets(i64 %34, i32 1, i32 7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%37 = load i64, i64* %2
%38 = call i32 @catclose(i64 %37)
ret i32 0
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [18 x i8] c"LC_MESSAGES = %s\0A\00"
@LC_MESSAGES = global i32 0
@.str.2 = [7 x i8] c"sample\00"
@NL_CAT_LOCALE = global i32 0
@.str.3 = [16 x i8] c"no catalog: %m\0A\00"
@.str.5 = [9 x i8] c"sample 1\00"
@.str.6 = [9 x i8] c"sample 2\00"
@.str.7 = [9 x i8] c"sample 3\00"
@.str.8 = [9 x i8] c"sample 4\00"
@.str.9 = [9 x i8] c"sample 5\00"
@.str.10 = [9 x i8] c"sample 6\00"
@.str.11 = [9 x i8] c"sample 7\00"
define i32 @main() {
%1 = load i32, i32* @LC_ALL
%2 = tail call i8* @setlocale(i32 %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @LC_MESSAGES
%4 = tail call i8* @setlocale(i32 %3, i8* null)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%6 = load i32, i32* @NL_CAT_LOCALE
%7 = tail call i64 @catopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = icmp eq i64 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = tail call i8* @catgets(i64 %7, i32 1, i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) %13)
%15 = tail call i8* @catgets(i64 %7, i32 1, i32 2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) %15)
%17 = tail call i8* @catgets(i64 %7, i32 1, i32 3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%18 = tail call i32 @puts(i8* dereferenceable(1) %17)
%19 = tail call i8* @catgets(i64 %7, i32 1, i32 4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%20 = tail call i32 @puts(i8* dereferenceable(1) %19)
%21 = tail call i8* @catgets(i64 %7, i32 1, i32 5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
%22 = tail call i32 @puts(i8* dereferenceable(1) %21)
%23 = tail call i8* @catgets(i64 %7, i32 1, i32 6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
%24 = tail call i32 @puts(i8* dereferenceable(1) %23)
%25 = tail call i8* @catgets(i64 %7, i32 1, i32 7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0))
%26 = tail call i32 @puts(i8* dereferenceable(1) %25)
%27 = tail call i32 @catclose(i64 %7)
ret i32 0
}