#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_ALL;
int /*<<< orphan*/ LC_CTYPE;
int /*<<< orphan*/ LC_NUMERIC;
int /*<<< orphan*/ asprintf(char **, char *, char *);
int /*<<< orphan*/ execve(char *, char **, char **);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
char *setlocale(int /*<<< orphan*/, char *);
scalar_t__ strcmp(char *, char *);
char *strdupa(char *);
int do_test(int argc, char *argv[]) {
  if (argc > 1) {
    char *newargv[5];
    asprintf(&newargv[0], "%self/ld.so", argv[1]);
    if (newargv[0] == NULL) {
      puts("asprintf failed");
      return 1;
    }
    newargv[1] = (char *)"--library-path";
    newargv[2] = argv[1];
    newargv[3] = argv[0];
    newargv[4] = NULL;
    char *env[3];
    env[0] = (char *)"LC_CTYPE=de_DE.UTF-8";
    char *loc = getenv("LOCPATH");
    if (loc == NULL || loc[0] == '\0') {
      puts("LOCPATH not set");
      return 1;
    }
    asprintf(&env[1], "LOCPATH=%s", loc);
    if (newargv[0] == NULL) {
      puts("second asprintf failed");
      return 1;
    }
    env[2] = NULL;
    execve(newargv[0], newargv, env);
    puts("execve returned");
    return 1;
  }
  int result = 0;
  char *a = setlocale(LC_ALL, "");
  printf("setlocale(LC_ALL, \"\") = %s\n", a);
  if (a == NULL)
    return 1;
  a = strdupa(a);
  char *b = setlocale(LC_CTYPE, "");
  printf("setlocale(LC_CTYPE, \"\") = %s\n", b);
  if (b == NULL)
    return 1;
  char *c = setlocale(LC_ALL, NULL);
  printf("setlocale(LC_ALL, NULL) = %s\n", c);
  if (c == NULL)
    return 1;
  c = strdupa(c);
  if (strcmp(a, c) != 0) {
    puts("*** first and third result do not match");
    result = 1;
  }
  char *d = setlocale(LC_NUMERIC, "");
  printf("setlocale(LC_NUMERIC, \"\") = %s\n", d);
  if (d == NULL)
    return 1;
  if (strcmp(d, "C") != 0) {
    puts("*** LC_NUMERIC not C");
    result = 1;
  }
  char *e = setlocale(LC_ALL, NULL);
  printf("setlocale(LC_ALL, NULL) = %s\n", e);
  if (e == NULL)
    return 1;
  if (strcmp(a, e) != 0) {
    puts("*** first and fifth result do not match");
    result = 1;
  }
  char *f = setlocale(LC_ALL, "C");
  printf("setlocale(LC_ALL, \"C\") = %s\n", f);
  if (f == NULL)
    return 1;
  if (strcmp(f, "C") != 0) {
    puts("*** LC_ALL not C");
    result = 1;
  }
  char *g = setlocale(LC_ALL, NULL);
  printf("setlocale(LC_ALL, NULL) = %s\n", g);
  if (g == NULL)
    return 1;
  if (strcmp(g, "C") != 0) {
    puts("*** LC_ALL not C");
    result = 1;
  }
  char *h = setlocale(LC_CTYPE, NULL);
  printf("setlocale(LC_CTYPE, NULL) = %s\n", h);
  if (h == NULL)
    return 1;
  if (strcmp(h, "C") != 0) {
    puts("*** LC_CTYPE not C");
    result = 1;
  }
  return result;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    12bb <do_test+0x13b>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe51(%rip),%rsi
call   1090 <asprintf@plt>
cmpq   $0x0,-0x40(%rbp)
jne    11d7 <do_test+0x57>
lea    0xe94(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    162c <do_test+0x4ac>
lea    0xe2e(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe13(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xe1d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     1237 <do_test+0xb7>
mov    -0x68(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    124f <do_test+0xcf>
lea    0xdfa(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    162c <do_test+0x4ac>
lea    -0x60(%rbp),%rdi
add    $0x8,%rdi
mov    -0x68(%rbp),%rdx
lea    0xde6(%rip),%rsi
call   1090 <asprintf@plt>
cmpq   $0x0,-0x40(%rbp)
jne    128a <do_test+0x10a>
lea    0xdda(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    162c <do_test+0x4ac>
movq   $0x0,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x60(%rbp),%rdx
call   1060 <execve@plt>
lea    0xdc0(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    162c <do_test+0x4ac>
movl   $0x0,-0x6c(%rbp)
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   10a0 <setlocale@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rsi
lea    0xd94(%rip),%rdi
call   1050 <printf@plt>
cmpq   $0x0,-0x78(%rbp)
jne    1302 <do_test+0x182>
movl   $0x1,-0x4(%rbp)
jmp    162c <do_test+0x4ac>
mov    -0x78(%rbp),%rdi
call   1080 <strdupa@plt>
mov    %rax,-0x78(%rbp)
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
call   10a0 <setlocale@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rsi
lea    0xd63(%rip),%rdi
call   1050 <printf@plt>
cmpq   $0x0,-0x80(%rbp)
jne    134f <do_test+0x1cf>
movl   $0x1,-0x4(%rbp)
jmp    162c <do_test+0x4ac>
mov    0x2c7a(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <setlocale@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rsi
lea    0xd3e(%rip),%rdi
call   1050 <printf@plt>
cmpq   $0x0,-0x88(%rbp)
jne    1395 <do_test+0x215>
movl   $0x1,-0x4(%rbp)
jmp    162c <do_test+0x4ac>
mov    -0x88(%rbp),%rdi
call   1080 <strdupa@plt>
mov    %rax,-0x88(%rbp)
mov    -0x78(%rbp),%rdi
mov    -0x88(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     13d5 <do_test+0x255>
lea    0xd09(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x6c(%rbp)
mov    0x2c04(%rip),%rax
mov    (%rax),%edi
lea    0xd34(%rip),%rsi
call   10a0 <setlocale@plt>
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rsi
lea    0xcfb(%rip),%rdi
call   1050 <printf@plt>
cmpq   $0x0,-0x90(%rbp)
jne    141e <do_test+0x29e>
movl   $0x1,-0x4(%rbp)
jmp    162c <do_test+0x4ac>
mov    -0x90(%rbp),%rdi
lea    0xd01(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     144e <do_test+0x2ce>
lea    0xcd8(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x6c(%rbp)
mov    0x2b7b(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <setlocale@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rsi
lea    0xc3f(%rip),%rdi
call   1050 <printf@plt>
cmpq   $0x0,-0x98(%rbp)
jne    1494 <do_test+0x314>
movl   $0x1,-0x4(%rbp)
jmp    162c <do_test+0x4ac>
mov    -0x78(%rbp),%rdi
mov    -0x98(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     14c1 <do_test+0x341>
lea    0xc7a(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x6c(%rbp)
mov    0x2b08(%rip),%rax
mov    (%rax),%edi
lea    0xc5c(%rip),%rsi
call   10a0 <setlocale@plt>
mov    %rax,-0xa0(%rbp)
mov    -0xa0(%rbp),%rsi
lea    0xc6c(%rip),%rdi
call   1050 <printf@plt>
cmpq   $0x0,-0xa0(%rbp)
jne    150a <do_test+0x38a>
movl   $0x1,-0x4(%rbp)
jmp    162c <do_test+0x4ac>
mov    -0xa0(%rbp),%rdi
lea    0xc15(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     153a <do_test+0x3ba>
lea    0xc46(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x6c(%rbp)
mov    0x2a8f(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <setlocale@plt>
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rsi
lea    0xb53(%rip),%rdi
call   1050 <printf@plt>
cmpq   $0x0,-0xa8(%rbp)
jne    1580 <do_test+0x400>
movl   $0x1,-0x4(%rbp)
jmp    162c <do_test+0x4ac>
mov    -0xa8(%rbp),%rdi
lea    0xb9f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     15b0 <do_test+0x430>
lea    0xbd0(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x6c(%rbp)
mov    0x2a31(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <setlocale@plt>
mov    %rax,-0xb0(%rbp)
mov    -0xb0(%rbp),%rsi
lea    0xbae(%rip),%rdi
call   1050 <printf@plt>
cmpq   $0x0,-0xb0(%rbp)
jne    15f6 <do_test+0x476>
movl   $0x1,-0x4(%rbp)
jmp    162c <do_test+0x4ac>
mov    -0xb0(%rbp),%rdi
lea    0xb29(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1626 <do_test+0x4a6>
lea    0xb8b(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
cmp    $0x2,%edi
jl     124f <do_test+0xcf>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdx
lea    0xe5c(%rip),%rsi
mov    %rsp,%rdi
call   1090 <asprintf@plt>
cmpq   $0x0,(%rsp)
je     1487 <do_test+0x307>
lea    0xe4e(%rip),%rax
mov    %rax,0x8(%rsp)
movdqu (%rbx),%xmm0
pshufd $0x4e,%xmm0,%xmm0
movdqa %xmm0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
lea    0xe39(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xe42(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe3e(%rip),%rdi
test   %rax,%rax
je     148e <do_test+0x30e>
cmpb   $0x0,(%rax)
je     148e <do_test+0x30e>
lea    0x38(%rsp),%rdi
lea    0xe30(%rip),%rsi
mov    %rax,%rdx
call   1090 <asprintf@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     14aa <do_test+0x32a>
movq   $0x0,0x40(%rsp)
mov    %rsp,%rsi
lea    0x30(%rsp),%rdx
call   1060 <execve@plt>
lea    0xe20(%rip),%rdi
jmp    148e <do_test+0x30e>
mov    0x2d7a(%rip),%r13
mov    0x0(%r13),%edi
lea    0xeb8(%rip),%rsi
call   10a0 <setlocale@plt>
mov    %rax,%rbx
lea    0xe0a(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
test   %rbx,%rbx
je     1493 <do_test+0x313>
mov    %rbx,%rdi
call   1080 <strdupa@plt>
mov    %rax,%r14
mov    0x2d55(%rip),%r12
mov    (%r12),%edi
lea    0xe7b(%rip),%rsi
call   10a0 <setlocale@plt>
mov    %rax,%rbx
lea    0xde9(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
test   %rbx,%rbx
je     1493 <do_test+0x313>
mov    0x0(%r13),%edi
xor    %r15d,%r15d
xor    %esi,%esi
call   10a0 <setlocale@plt>
mov    %rax,%rbx
lea    0xdde(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
test   %rbx,%rbx
je     1493 <do_test+0x313>
mov    %rbx,%rdi
call   1080 <strdupa@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1311 <do_test+0x191>
lea    0xdcc(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
lea    0xdf8(%rip),%rsi
call   10a0 <setlocale@plt>
mov    %rax,%rbx
lea    0xdca(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
test   %rbx,%rbx
je     1493 <do_test+0x313>
lea    0xde5(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1367 <do_test+0x1e7>
lea    0xdbe(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
mov    0x0(%r13),%edi
xor    %esi,%esi
call   10a0 <setlocale@plt>
mov    %rax,%rbx
lea    0xd38(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
test   %rbx,%rbx
je     1493 <do_test+0x313>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     13af <do_test+0x22f>
lea    0xd8b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
mov    0x0(%r13),%edi
lea    0xd73(%rip),%rsi
call   10a0 <setlocale@plt>
mov    %rax,%rbx
lea    0xd8e(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
test   %rbx,%rbx
je     1493 <do_test+0x313>
lea    0xd4c(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1400 <do_test+0x280>
lea    0xd7f(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
mov    0x0(%r13),%edi
xor    %esi,%esi
call   10a0 <setlocale@plt>
mov    %rax,%rbx
lea    0xc9f(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
test   %rbx,%rbx
je     1493 <do_test+0x313>
lea    0xd04(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1448 <do_test+0x2c8>
lea    0xd37(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
mov    (%r12),%edi
xor    %esi,%esi
call   10a0 <setlocale@plt>
mov    %rax,%rbx
lea    0xd28(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
test   %rbx,%rbx
je     1493 <do_test+0x313>
lea    0xcbc(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1499 <do_test+0x319>
lea    0xd20(%rip),%rdi
jmp    148e <do_test+0x30e>
lea    0xbcc(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xba2(%rip),%rdi
jmp    148e <do_test+0x30e>

LLVM IR (-O0):
@.str = [12 x i8] c"%self/ld.so\00"
@.str.1 = [16 x i8] c"asprintf failed\00"
@.str.2 = [15 x i8] c"--library-path\00"
@.str.3 = [21 x i8] c"LC_CTYPE=de_DE.UTF-8\00"
@.str.4 = [8 x i8] c"LOCPATH\00"
@.str.5 = [16 x i8] c"LOCPATH not set\00"
@.str.6 = [11 x i8] c"LOCPATH=%s\00"
@.str.7 = [23 x i8] c"second asprintf failed\00"
@.str.8 = [16 x i8] c"execve returned\00"
@LC_ALL = global i32 0
@.str.9 = [1 x i8] zeroinitializer
@.str.10 = [28 x i8] c"setlocale(LC_ALL, \22\22) = %s\0A\00"
@LC_CTYPE = global i32 0
@.str.11 = [30 x i8] c"setlocale(LC_CTYPE, \22\22) = %s\0A\00"
@.str.12 = [30 x i8] c"setlocale(LC_ALL, NULL) = %s\0A\00"
@.str.13 = [40 x i8] c"*** first and third result do not match\00"
@LC_NUMERIC = global i32 0
@.str.14 = [32 x i8] c"setlocale(LC_NUMERIC, \22\22) = %s\0A\00"
@.str.15 = [2 x i8] c"C\00"
@.str.16 = [21 x i8] c"*** LC_NUMERIC not C\00"
@.str.17 = [40 x i8] c"*** first and fifth result do not match\00"
@.str.18 = [29 x i8] c"setlocale(LC_ALL, \22C\22) = %s\0A\00"
@.str.19 = [17 x i8] c"*** LC_ALL not C\00"
@.str.20 = [32 x i8] c"setlocale(LC_CTYPE, NULL) = %s\0A\00"
@.str.21 = [19 x i8] c"*** LC_CTYPE not C\00"
define i32 @do_test(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [5 x i8*]
%7 = alloca [3 x i8*]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 1
br i1 %19, label %20, label %71
20: ; preds = %2
%21 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 0
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @asprintf(i8** %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 0
%27 = load i8*, i8** %26
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %20
%30 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %179
31: ; preds = %20
%32 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8** %32
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 2
store i8* %35, i8** %36
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 3
store i8* %39, i8** %40
%41 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 4
store i8* null, i8** %41
%42 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 0
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8** %42
%43 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
store i8* %43, i8** %8
%44 = load i8*, i8** %8
%45 = icmp eq i8* %44, null
br i1 %45, label %52, label %46
46: ; preds = %31
%47 = load i8*, i8** %8
%48 = getelementptr inbounds i8, i8* %47, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %46, %31
%53 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %179
54: ; preds = %46
%55 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 1
%56 = load i8*, i8** %8
%57 = call i32 @asprintf(i8** %55, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %56)
%58 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 0
%59 = load i8*, i8** %58
%60 = icmp eq i8* %59, null
br i1 %60, label %61, label %63
61: ; preds = %54
%62 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %179
63: ; preds = %54
%64 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 2
store i8* null, i8** %64
%65 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 0
%66 = load i8*, i8** %65
%67 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 0
%68 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 0
%69 = call i32 @execve(i8* %66, i8** %67, i8** %68)
%70 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %179
71: ; preds = %2
store i32 0, i32* %9
%72 = load i32, i32* @LC_ALL
%73 = call i8* @setlocale(i32 %72, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.9, i64 0, i64 0))
store i8* %73, i8** %10
%74 = load i8*, i8** %10
%75 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0), i8* %74)
%76 = load i8*, i8** %10
%77 = icmp eq i8* %76, null
br i1 %77, label %78, label %79
78: ; preds = %71
store i32 1, i32* %3
br label %179
79: ; preds = %71
%80 = load i8*, i8** %10
%81 = call i8* @strdupa(i8* %80)
store i8* %81, i8** %10
%82 = load i32, i32* @LC_CTYPE
%83 = call i8* @setlocale(i32 %82, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.9, i64 0, i64 0))
store i8* %83, i8** %11
%84 = load i8*, i8** %11
%85 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0), i8* %84)
%86 = load i8*, i8** %11
%87 = icmp eq i8* %86, null
br i1 %87, label %88, label %89
88: ; preds = %79
store i32 1, i32* %3
br label %179
89: ; preds = %79
%90 = load i32, i32* @LC_ALL
%91 = call i8* @setlocale(i32 %90, i8* null)
store i8* %91, i8** %12
%92 = load i8*, i8** %12
%93 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0), i8* %92)
%94 = load i8*, i8** %12
%95 = icmp eq i8* %94, null
br i1 %95, label %96, label %97
96: ; preds = %89
store i32 1, i32* %3
br label %179
97: ; preds = %89
%98 = load i8*, i8** %12
%99 = call i8* @strdupa(i8* %98)
store i8* %99, i8** %12
%100 = load i8*, i8** %10
%101 = load i8*, i8** %12
%102 = call i64 @strcmp(i8* %100, i8* %101)
%103 = icmp ne i64 %102, 0
br i1 %103, label %104, label %106
104: ; preds = %97
%105 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.13, i64 0, i64 0))
store i32 1, i32* %9
br label %106
106: ; preds = %104, %97
%107 = load i32, i32* @LC_NUMERIC
%108 = call i8* @setlocale(i32 %107, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.9, i64 0, i64 0))
store i8* %108, i8** %13
%109 = load i8*, i8** %13
%110 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.14, i64 0, i64 0), i8* %109)
%111 = load i8*, i8** %13
%112 = icmp eq i8* %111, null
br i1 %112, label %113, label %114
113: ; preds = %106
store i32 1, i32* %3
br label %179
114: ; preds = %106
%115 = load i8*, i8** %13
%116 = call i64 @strcmp(i8* %115, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
%117 = icmp ne i64 %116, 0
br i1 %117, label %118, label %120
118: ; preds = %114
%119 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.16, i64 0, i64 0))
store i32 1, i32* %9
br label %120
120: ; preds = %118, %114
%121 = load i32, i32* @LC_ALL
%122 = call i8* @setlocale(i32 %121, i8* null)
store i8* %122, i8** %14
%123 = load i8*, i8** %14
%124 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0), i8* %123)
%125 = load i8*, i8** %14
%126 = icmp eq i8* %125, null
br i1 %126, label %127, label %128
127: ; preds = %120
store i32 1, i32* %3
br label %179
128: ; preds = %120
%129 = load i8*, i8** %10
%130 = load i8*, i8** %14
%131 = call i64 @strcmp(i8* %129, i8* %130)
%132 = icmp ne i64 %131, 0
br i1 %132, label %133, label %135
133: ; preds = %128
%134 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.17, i64 0, i64 0))
store i32 1, i32* %9
br label %135
135: ; preds = %133, %128
%136 = load i32, i32* @LC_ALL
%137 = call i8* @setlocale(i32 %136, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
store i8* %137, i8** %15
%138 = load i8*, i8** %15
%139 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.18, i64 0, i64 0), i8* %138)
%140 = load i8*, i8** %15
%141 = icmp eq i8* %140, null
br i1 %141, label %142, label %143
142: ; preds = %135
store i32 1, i32* %3
br label %179
143: ; preds = %135
%144 = load i8*, i8** %15
%145 = call i64 @strcmp(i8* %144, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
%146 = icmp ne i64 %145, 0
br i1 %146, label %147, label %149
147: ; preds = %143
%148 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.19, i64 0, i64 0))
store i32 1, i32* %9
br label %149
149: ; preds = %147, %143
%150 = load i32, i32* @LC_ALL
%151 = call i8* @setlocale(i32 %150, i8* null)
store i8* %151, i8** %16
%152 = load i8*, i8** %16
%153 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0), i8* %152)
%154 = load i8*, i8** %16
%155 = icmp eq i8* %154, null
br i1 %155, label %156, label %157
156: ; preds = %149
store i32 1, i32* %3
br label %179
157: ; preds = %149
%158 = load i8*, i8** %16
%159 = call i64 @strcmp(i8* %158, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
%160 = icmp ne i64 %159, 0
br i1 %160, label %161, label %163
161: ; preds = %157
%162 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.19, i64 0, i64 0))
store i32 1, i32* %9
br label %163
163: ; preds = %161, %157
%164 = load i32, i32* @LC_CTYPE
%165 = call i8* @setlocale(i32 %164, i8* null)
store i8* %165, i8** %17
%166 = load i8*, i8** %17
%167 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.20, i64 0, i64 0), i8* %166)
%168 = load i8*, i8** %17
%169 = icmp eq i8* %168, null
br i1 %169, label %170, label %171
170: ; preds = %163
store i32 1, i32* %3
br label %179
171: ; preds = %163
%172 = load i8*, i8** %17
%173 = call i64 @strcmp(i8* %172, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
%174 = icmp ne i64 %173, 0
br i1 %174, label %175, label %177
175: ; preds = %171
%176 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.21, i64 0, i64 0))
store i32 1, i32* %9
br label %177
177: ; preds = %175, %171
%178 = load i32, i32* %9
store i32 %178, i32* %3
br label %179
179: ; preds = %177, %170, %156, %142, %127, %113, %96, %88, %78, %63, %61, %52, %29
%180 = load i32, i32* %3
ret i32 %180
}

LLVM IR (-O2):
@.str = [12 x i8] c"%self/ld.so\00"
@.str.1 = [16 x i8] c"asprintf failed\00"
@.str.2 = [15 x i8] c"--library-path\00"
@.str.3 = [21 x i8] c"LC_CTYPE=de_DE.UTF-8\00"
@.str.4 = [8 x i8] c"LOCPATH\00"
@.str.5 = [16 x i8] c"LOCPATH not set\00"
@.str.6 = [11 x i8] c"LOCPATH=%s\00"
@.str.7 = [23 x i8] c"second asprintf failed\00"
@.str.8 = [16 x i8] c"execve returned\00"
@LC_ALL = global i32 0
@.str.9 = [1 x i8] zeroinitializer
@.str.10 = [28 x i8] c"setlocale(LC_ALL, \22\22) = %s\0A\00"
@LC_CTYPE = global i32 0
@.str.11 = [30 x i8] c"setlocale(LC_CTYPE, \22\22) = %s\0A\00"
@.str.12 = [30 x i8] c"setlocale(LC_ALL, NULL) = %s\0A\00"
@.str.13 = [40 x i8] c"*** first and third result do not match\00"
@LC_NUMERIC = global i32 0
@.str.14 = [32 x i8] c"setlocale(LC_NUMERIC, \22\22) = %s\0A\00"
@.str.15 = [2 x i8] c"C\00"
@.str.16 = [21 x i8] c"*** LC_NUMERIC not C\00"
@.str.17 = [40 x i8] c"*** first and fifth result do not match\00"
@.str.18 = [29 x i8] c"setlocale(LC_ALL, \22C\22) = %s\0A\00"
@.str.19 = [17 x i8] c"*** LC_ALL not C\00"
@.str.20 = [32 x i8] c"setlocale(LC_CTYPE, NULL) = %s\0A\00"
@.str.21 = [19 x i8] c"*** LC_CTYPE not C\00"
define i32 @do_test(i32 %0, i8** nocapture %1) {
%3 = alloca [5 x i8*]
%4 = alloca [3 x i8*]
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %43
6: ; preds = %2
%7 = bitcast [5 x i8*]* %3 to i8*
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 0
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @asprintf(i8** %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %42
16: ; preds = %6
%17 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 2
%19 = bitcast i8** %1 to <2 x i8*>*
%20 = load <2 x i8*>, <2 x i8*>* %19
%21 = shufflevector <2 x i8*> %20, <2 x i8*> poison, <2 x i32> <i32 1, i32 0>
%22 = bitcast i8** %18 to <2 x i8*>*
store <2 x i8*> %21, <2 x i8*>* %22
%23 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 4
store i8* null, i8** %23
%24 = bitcast [3 x i8*]* %4 to i8*
%25 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8** %25
%26 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i8* %26, null
br i1 %27, label %39, label %28
28: ; preds = %16
%29 = load i8, i8* %26
%30 = icmp eq i8 %29, 0
br i1 %30, label %39, label %31
31: ; preds = %28
%32 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 1
%33 = call i32 @asprintf(i8** %32, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %26)
%34 = load i8*, i8** %8
%35 = icmp eq i8* %34, null
br i1 %35, label %39, label %36
36: ; preds = %31
%37 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 2
store i8* null, i8** %37
%38 = call i32 @execve(i8* %34, i8** %8, i8** %25)
br label %39
39: ; preds = %31, %16, %28, %36
%40 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), %36 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), %28 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), %16 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), %31 ]
%41 = call i32 @puts(i8* dereferenceable(1) %40)
br label %42
42: ; preds = %39, %14
br label %120
43: ; preds = %2
%44 = load i32, i32* @LC_ALL
%45 = tail call i8* @setlocale(i32 %44, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.9, i64 0, i64 0))
%46 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0), i8* %45)
%47 = icmp eq i8* %45, null
br i1 %47, label %120, label %48
48: ; preds = %43
%49 = tail call i8* @strdupa(i8* %45)
%50 = load i32, i32* @LC_CTYPE
%51 = tail call i8* @setlocale(i32 %50, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.9, i64 0, i64 0))
%52 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0), i8* %51)
%53 = icmp eq i8* %51, null
br i1 %53, label %120, label %54
54: ; preds = %48
%55 = load i32, i32* @LC_ALL
%56 = tail call i8* @setlocale(i32 %55, i8* null)
%57 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0), i8* %56)
%58 = icmp eq i8* %56, null
br i1 %58, label %120, label %59
59: ; preds = %54
%60 = tail call i8* @strdupa(i8* %56)
%61 = tail call i64 @strcmp(i8* %49, i8* %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %65, label %63
63: ; preds = %59
%64 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.13, i64 0, i64 0))
br label %65
65: ; preds = %63, %59
%66 = phi i32 [ 1, %63 ], [ 0, %59 ]
%67 = load i32, i32* @LC_NUMERIC
%68 = tail call i8* @setlocale(i32 %67, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.9, i64 0, i64 0))
%69 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.14, i64 0, i64 0), i8* %68)
%70 = icmp eq i8* %68, null
br i1 %70, label %120, label %71
71: ; preds = %65
%72 = tail call i64 @strcmp(i8* %68, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
%73 = icmp eq i64 %72, 0
br i1 %73, label %76, label %74
74: ; preds = %71
%75 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.16, i64 0, i64 0))
br label %76
76: ; preds = %74, %71
%77 = phi i32 [ 1, %74 ], [ %66, %71 ]
%78 = load i32, i32* @LC_ALL
%79 = tail call i8* @setlocale(i32 %78, i8* null)
%80 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0), i8* %79)
%81 = icmp eq i8* %79, null
br i1 %81, label %120, label %82
82: ; preds = %76
%83 = tail call i64 @strcmp(i8* %49, i8* %79)
%84 = icmp eq i64 %83, 0
br i1 %84, label %87, label %85
85: ; preds = %82
%86 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.17, i64 0, i64 0))
br label %87
87: ; preds = %85, %82
%88 = phi i32 [ 1, %85 ], [ %77, %82 ]
%89 = load i32, i32* @LC_ALL
%90 = tail call i8* @setlocale(i32 %89, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
%91 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.18, i64 0, i64 0), i8* %90)
%92 = icmp eq i8* %90, null
br i1 %92, label %120, label %93
93: ; preds = %87
%94 = tail call i64 @strcmp(i8* %90, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
%95 = icmp eq i64 %94, 0
br i1 %95, label %98, label %96
96: ; preds = %93
%97 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.19, i64 0, i64 0))
br label %98
98: ; preds = %96, %93
%99 = phi i32 [ 1, %96 ], [ %88, %93 ]
%100 = load i32, i32* @LC_ALL
%101 = tail call i8* @setlocale(i32 %100, i8* null)
%102 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0), i8* %101)
%103 = icmp eq i8* %101, null
br i1 %103, label %120, label %104
104: ; preds = %98
%105 = tail call i64 @strcmp(i8* %101, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
%106 = icmp eq i64 %105, 0
br i1 %106, label %109, label %107
107: ; preds = %104
%108 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.19, i64 0, i64 0))
br label %109
109: ; preds = %107, %104
%110 = phi i32 [ 1, %107 ], [ %99, %104 ]
%111 = load i32, i32* @LC_CTYPE
%112 = tail call i8* @setlocale(i32 %111, i8* null)
%113 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.20, i64 0, i64 0), i8* %112)
%114 = icmp eq i8* %112, null
br i1 %114, label %120, label %115
115: ; preds = %109
%116 = tail call i64 @strcmp(i8* %112, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
%117 = icmp eq i64 %116, 0
br i1 %117, label %120, label %118
118: ; preds = %115
%119 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.21, i64 0, i64 0))
br label %120
120: ; preds = %43, %54, %76, %98, %115, %118, %109, %87, %65, %48, %42
%121 = phi i32 [ 1, %42 ], [ 1, %43 ], [ 1, %48 ], [ 1, %54 ], [ 1, %65 ], [ 1, %76 ], [ 1, %87 ], [ 1, %98 ], [ 1, %109 ], [ 1, %118 ], [ %110, %115 ]
ret i32 %121
}