#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_MESSAGES;
char *dcngettext(char *, char const *, char const *, unsigned long,
                 int /*<<< orphan*/);
char *dngettext(char *, char const *, char const *, unsigned long);
char *ngettext(char const *, char const *, unsigned long);
int /*<<< orphan*/ printf(char *, unsigned long, char *);
int /*<<< orphan*/ setenv(char *, char *, int);
scalar_t__ strcmp(char *, char const *);
int /*<<< orphan*/ unsetenv(char *);
int main(void) {
  const char *strs[2] = {"singular", "plural"};
  unsigned long int i;
  int res = 0;
  setenv("LANGUAGE", "C", 1);
  unsetenv("OUTPUT_CHARSET");
  for (i = 0; i < 30; ++i) {
    char *tr;
    tr = ngettext(strs[0], strs[1], i);
    do
      if (tr != strs[i != 1]) {
        if (strcmp(tr, strs[i != 1]) == 0)
          printf("%lu: correct string, wrong pointer (%s)\n", i, tr);
        else
          printf("%lu: wrong result (%s)\n", i, tr);
        res = 1;
      }
    while (0);
    tr = dngettext("messages", strs[0], strs[1], i);
    do
      if (tr != strs[i != 1]) {
        if (strcmp(tr, strs[i != 1]) == 0)
          printf("%lu: correct string, wrong pointer (%s)\n", i, tr);
        else
          printf("%lu: wrong result (%s)\n", i, tr);
        res = 1;
      }
    while (0);
    tr = dcngettext("messages", strs[0], strs[1], i, LC_MESSAGES);
    do
      if (tr != strs[i != 1]) {
        if (strcmp(tr, strs[i != 1]) == 0)
          printf("%lu: correct string, wrong pointer (%s)\n", i, tr);
        else
          printf("%lu: wrong result (%s)\n", i, tr);
        res = 1;
      }
    while (0);
  }
  return res;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2c7a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c77(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    0xe6d(%rip),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
lea    0xe60(%rip),%rdi
call   1070 <unsetenv@plt>
movq   $0x0,-0x28(%rbp)
cmpq   $0x1e,-0x28(%rbp)
jae    13c0 <main+0x250>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1080 <ngettext@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpq   $0x1,-0x28(%rbp)
setne  %cl
and    $0x1,%cl
movzbl %cl,%ecx
movslq %ecx,%rcx
cmp    -0x20(%rbp,%rcx,8),%rax
je     1263 <main+0xf3>
mov    -0x38(%rbp),%rdi
cmpq   $0x1,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
cltq
mov    -0x20(%rbp,%rax,8),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1248 <main+0xd8>
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xdec(%rip),%rdi
call   1040 <printf@plt>
jmp    125c <main+0xec>
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xdfc(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x2c(%rbp)
jmp    1268 <main+0xf8>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xdf0(%rip),%rdi
call   1090 <dngettext@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpq   $0x1,-0x28(%rbp)
setne  %cl
and    $0x1,%cl
movzbl %cl,%ecx
movslq %ecx,%rcx
cmp    -0x20(%rbp,%rcx,8),%rax
je     12ff <main+0x18f>
mov    -0x38(%rbp),%rdi
cmpq   $0x1,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
cltq
mov    -0x20(%rbp,%rax,8),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12e4 <main+0x174>
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xd50(%rip),%rdi
call   1040 <printf@plt>
jmp    12f8 <main+0x188>
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xd60(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x2c(%rbp)
jmp    1304 <main+0x194>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    0x2cc1(%rip),%rax
mov    (%rax),%r8d
lea    0xd4a(%rip),%rdi
call   1060 <dcngettext@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpq   $0x1,-0x28(%rbp)
setne  %cl
and    $0x1,%cl
movzbl %cl,%ecx
movslq %ecx,%rcx
cmp    -0x20(%rbp,%rcx,8),%rax
je     13a5 <main+0x235>
mov    -0x38(%rbp),%rdi
cmpq   $0x1,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
cltq
mov    -0x20(%rbp,%rax,8),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    138a <main+0x21a>
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xcaa(%rip),%rdi
call   1040 <printf@plt>
jmp    139e <main+0x22e>
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xcba(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x2c(%rbp)
jmp    13aa <main+0x23a>
jmp    13af <main+0x23f>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11c8 <main+0x58>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe8e(%rip),%rdi
lea    0xe90(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
lea    0xe81(%rip),%rdi
call   1070 <unsetenv@plt>
xor    %r13d,%r13d
lea    0xe57(%rip),%r15
lea    0xe59(%rip),%r12
xor    %ebx,%ebx
jmp    11ce <main+0x5e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cmp    $0x1e,%rbx
je     12de <main+0x16e>
mov    %r15,%rbp
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1080 <ngettext@plt>
mov    %rax,%r15
xor    %eax,%eax
cmp    $0x1,%rbx
setne  %al
lea    0x2c0e(%rip),%rcx
mov    (%rcx,%rax,8),%r14
cmp    %r14,%r15
je     122c <main+0xbc>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
lea    0xe43(%rip),%rdi
lea    0xe13(%rip),%rax
cmove  %rax,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <printf@plt>
mov    $0x1,%r13d
lea    0xe38(%rip),%rdi
mov    %rbp,%r15
mov    %rbp,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1090 <dngettext@plt>
cmp    %r14,%rax
je     127d <main+0x10d>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
lea    0xdf2(%rip),%rdi
lea    0xdc2(%rip),%rax
cmove  %rax,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1040 <printf@plt>
mov    $0x1,%r13d
mov    0x2d54(%rip),%rax
mov    (%rax),%r8d
lea    0xddd(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1060 <dcngettext@plt>
cmp    %r14,%rax
je     11c0 <main+0x50>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
lea    0xd96(%rip),%rdi
lea    0xd66(%rip),%rax
cmove  %rax,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1040 <printf@plt>
mov    $0x1,%r13d
jmp    11c0 <main+0x50>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"singular\00"
@.str.1 = [7 x i8] c"plural\00"
@__const.main.strs = [2 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0)]
@.str.2 = [9 x i8] c"LANGUAGE\00"
@.str.3 = [2 x i8] c"C\00"
@.str.4 = [15 x i8] c"OUTPUT_CHARSET\00"
@.str.5 = [41 x i8] c"%lu: correct string, wrong pointer (%s)\0A\00"
@.str.6 = [24 x i8] c"%lu: wrong result (%s)\0A\00"
@.str.7 = [9 x i8] c"messages\00"
@LC_MESSAGES = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i8*]
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = bitcast [2 x i8*]* %2 to i8*
store i32 0, i32* %4
%7 = call i32 @setenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%8 = call i32 @unsetenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
store i64 0, i64* %3
br label %9
9: ; preds = %122, %0
%10 = load i64, i64* %3
%11 = icmp ult i64 %10, 30
br i1 %11, label %12, label %125
12: ; preds = %9
%13 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%14 = load i8*, i8** %13
%15 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 1
%16 = load i8*, i8** %15
%17 = load i64, i64* %3
%18 = call i8* @ngettext(i8* %14, i8* %16, i64 %17)
store i8* %18, i8** %5
br label %19
19: ; preds = %12
%20 = load i8*, i8** %5
%21 = load i64, i64* %3
%22 = icmp ne i64 %21, 1
%23 = zext i1 %22 to i32
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = icmp ne i8* %20, %26
br i1 %27, label %28, label %47
28: ; preds = %19
%29 = load i8*, i8** %5
%30 = load i64, i64* %3
%31 = icmp ne i64 %30, 1
%32 = zext i1 %31 to i32
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 %33
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* %29, i8* %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %28
%39 = load i64, i64* %3
%40 = load i8*, i8** %5
%41 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i64 %39, i8* %40)
br label %46
42: ; preds = %28
%43 = load i64, i64* %3
%44 = load i8*, i8** %5
%45 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i64 %43, i8* %44)
br label %46
46: ; preds = %42, %38
store i32 1, i32* %4
br label %47
47: ; preds = %46, %19
br label %48
48: ; preds = %47
%49 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%50 = load i8*, i8** %49
%51 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 1
%52 = load i8*, i8** %51
%53 = load i64, i64* %3
%54 = call i8* @dngettext(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* %50, i8* %52, i64 %53)
store i8* %54, i8** %5
br label %55
55: ; preds = %48
%56 = load i8*, i8** %5
%57 = load i64, i64* %3
%58 = icmp ne i64 %57, 1
%59 = zext i1 %58 to i32
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 %60
%62 = load i8*, i8** %61
%63 = icmp ne i8* %56, %62
br i1 %63, label %64, label %83
64: ; preds = %55
%65 = load i8*, i8** %5
%66 = load i64, i64* %3
%67 = icmp ne i64 %66, 1
%68 = zext i1 %67 to i32
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 %69
%71 = load i8*, i8** %70
%72 = call i64 @strcmp(i8* %65, i8* %71)
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %64
%75 = load i64, i64* %3
%76 = load i8*, i8** %5
%77 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i64 %75, i8* %76)
br label %82
78: ; preds = %64
%79 = load i64, i64* %3
%80 = load i8*, i8** %5
%81 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i64 %79, i8* %80)
br label %82
82: ; preds = %78, %74
store i32 1, i32* %4
br label %83
83: ; preds = %82, %55
br label %84
84: ; preds = %83
%85 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%86 = load i8*, i8** %85
%87 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 1
%88 = load i8*, i8** %87
%89 = load i64, i64* %3
%90 = load i32, i32* @LC_MESSAGES
%91 = call i8* @dcngettext(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* %86, i8* %88, i64 %89, i32 %90)
store i8* %91, i8** %5
br label %92
92: ; preds = %84
%93 = load i8*, i8** %5
%94 = load i64, i64* %3
%95 = icmp ne i64 %94, 1
%96 = zext i1 %95 to i32
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 %97
%99 = load i8*, i8** %98
%100 = icmp ne i8* %93, %99
br i1 %100, label %101, label %120
101: ; preds = %92
%102 = load i8*, i8** %5
%103 = load i64, i64* %3
%104 = icmp ne i64 %103, 1
%105 = zext i1 %104 to i32
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 %106
%108 = load i8*, i8** %107
%109 = call i64 @strcmp(i8* %102, i8* %108)
%110 = icmp eq i64 %109, 0
br i1 %110, label %111, label %115
111: ; preds = %101
%112 = load i64, i64* %3
%113 = load i8*, i8** %5
%114 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i64 %112, i8* %113)
br label %119
115: ; preds = %101
%116 = load i64, i64* %3
%117 = load i8*, i8** %5
%118 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i64 %116, i8* %117)
br label %119
119: ; preds = %115, %111
store i32 1, i32* %4
br label %120
120: ; preds = %119, %92
br label %121
121: ; preds = %120
br label %122
122: ; preds = %121
%123 = load i64, i64* %3
%124 = add i64 %123, 1
store i64 %124, i64* %3
br label %9
125: ; preds = %9
%126 = load i32, i32* %4
ret i32 %126
}

LLVM IR (-O2):
@.str = [9 x i8] c"singular\00"
@.str.1 = [7 x i8] c"plural\00"
@__const.main.strs = [2 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0)]
@.str.2 = [9 x i8] c"LANGUAGE\00"
@.str.3 = [2 x i8] c"C\00"
@.str.4 = [15 x i8] c"OUTPUT_CHARSET\00"
@.str.5 = [41 x i8] c"%lu: correct string, wrong pointer (%s)\0A\00"
@.str.6 = [24 x i8] c"%lu: wrong result (%s)\0A\00"
@.str.7 = [9 x i8] c"messages\00"
@LC_MESSAGES = global i32 0
define i32 @main() {
%1 = tail call i32 @setenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%2 = tail call i32 @unsetenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %3
3: ; preds = %0, %36
%4 = phi i32 [ 0, %0 ], [ %37, %36 ]
%5 = phi i64 [ 0, %0 ], [ %38, %36 ]
%6 = tail call i8* @ngettext(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %5)
%7 = icmp ne i64 %5, 1
%8 = zext i1 %7 to i64
%9 = getelementptr inbounds [2 x i8*], [2 x i8*]* @__const.main.strs, i64 0, i64 %8
%10 = load i8*, i8** %9
%11 = icmp eq i8* %6, %10
br i1 %11, label %17, label %12
12: ; preds = %3
%13 = tail call i64 @strcmp(i8* %6, i8* %10)
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0)
%16 = tail call i32 @printf(i8* %15, i64 %5, i8* %6)
br label %17
17: ; preds = %12, %3
%18 = phi i32 [ %4, %3 ], [ 1, %12 ]
%19 = tail call i8* @dngettext(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %5)
%20 = icmp eq i8* %19, %10
br i1 %20, label %26, label %21
21: ; preds = %17
%22 = tail call i64 @strcmp(i8* %19, i8* %10)
%23 = icmp eq i64 %22, 0
%24 = select i1 %23, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0)
%25 = tail call i32 @printf(i8* %24, i64 %5, i8* %19)
br label %26
26: ; preds = %21, %17
%27 = phi i32 [ %18, %17 ], [ 1, %21 ]
%28 = load i32, i32* @LC_MESSAGES
%29 = tail call i8* @dcngettext(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %5, i32 %28)
%30 = icmp eq i8* %29, %10
br i1 %30, label %36, label %31
31: ; preds = %26
%32 = tail call i64 @strcmp(i8* %29, i8* %10)
%33 = icmp eq i64 %32, 0
%34 = select i1 %33, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0)
%35 = tail call i32 @printf(i8* %34, i64 %5, i8* %29)
br label %36
36: ; preds = %31, %26
%37 = phi i32 [ %27, %26 ], [ 1, %31 ]
%38 = add nuw nsw i64 %5, 1
%39 = icmp eq i64 %38, 30
br i1 %39, label %40, label %3
40: ; preds = %36
ret i32 %37
}