#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*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int execve(char *, char **, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int load_nl_args_file(char *, int *, char ***, char **);
char **malloc(int);
int /*<<< orphan*/ memcpy(char **, char **, int);
int /*<<< orphan*/ print_str_array(int, char **, int /*<<< orphan*/);
char **realloc(char **, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ test();
int main(int argc, char **argv, char **envp) {
  test();
  fprintf(stderr, "m: ");
  print_str_array(argc, argv, stderr);
  fprintf(stderr, "\n");
  char **newargv = malloc(sizeof(*newargv) * 1);
  int arg_offs = 1;
  char *buf;
  int r = load_nl_args_file("/etc/qemu-user-env", &arg_offs, &newargv, &buf);
  if (r < 0) {
    exit(EXIT_FAILURE);
  }
  newargv[0] = argv[0];
  fprintf(stderr, "e: ");
  print_str_array(arg_offs, newargv, stderr);
  fprintf(stderr, "\n");
  char **nnargv = realloc(newargv, sizeof(*newargv) * (arg_offs + argc));
  if (!nnargv) {
    fprintf(stderr, "realloc for args failed\n");
    exit(EXIT_FAILURE);
  }
  newargv = nnargv;
  memcpy(&newargv[arg_offs], &argv[1], sizeof(*argv) * (argc - 1));
  newargv[argc + arg_offs - 1] = NULL;
  r = execve("/usr/bin/qemu-ppc-static.real", newargv, envp);
  if (r < 0) {
    fprintf(stderr, "qemu-user-env: execve failed: %s\n", strerror(errno));
  }
  return r;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   10c0 <test@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
call   1070 <print_str_array@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x8,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
lea    0xde4(%rip),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1050 <load_nl_args_file@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    124c <main+0xac>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    0x2d61(%rip),%rax
mov    (%rax),%edx
call   1070 <print_str_array@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    -0x8(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1090 <realloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12e8 <main+0x148>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
lea    0xd48(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2cef(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xcf3(%rip),%rdi
call   1030 <execve@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1381 <main+0x1e1>
mov    0x2c86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2c72(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xcd8(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
xor    %eax,%eax
call   10c0 <test@plt>
mov    0x2e1f(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe35(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%rbp),%edx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1070 <print_str_array@plt>
mov    0x0(%rbp),%edi
lea    0xe48(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x8,%edi
call   1080 <malloc@plt>
mov    %rax,0x8(%rsp)
movl   $0x1,0x4(%rsp)
lea    0xdf5(%rip),%rdi
lea    0x4(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1050 <load_nl_args_file@plt>
test   %eax,%eax
js     131e <main+0x17e>
mov    (%rbx),%rax
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx)
mov    0x0(%rbp),%edi
lea    0xdd7(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x4(%rsp),%edi
mov    0x8(%rsp),%rsi
mov    0x0(%rbp),%edx
call   1070 <print_str_array@plt>
mov    0x0(%rbp),%edi
lea    0xdd0(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x8(%rsp),%rdi
mov    0x4(%rsp),%esi
add    %r15d,%esi
shl    $0x3,%esi
call   1090 <realloc@plt>
test   %rax,%rax
je     130d <main+0x16d>
mov    %rax,0x8(%rsp)
movslq 0x4(%rsp),%rcx
lea    (%rax,%rcx,8),%rdi
add    $0x8,%rbx
lea    -0x8(,%r15,8),%edx
ff
mov    %rbx,%rsi
call   1060 <memcpy@plt>
mov    0x8(%rsp),%rax
mov    0x4(%rsp),%ecx
add    %r15d,%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x8(%rsp),%rsi
lea    0xd66(%rip),%rdi
mov    %r14,%rdx
call   1030 <execve@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1300 <main+0x160>
mov    0x0(%rbp),%ebp
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd5e(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%rbp),%edi
lea    0xd04(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [4 x i8] c"m: \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [19 x i8] c"/etc/qemu-user-env\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"e: \00"
@.str.4 = [25 x i8] c"realloc for args failed\0A\00"
@.str.5 = [30 x i8] c"/usr/bin/qemu-ppc-static.real\00"
@.str.6 = [34 x i8] c"qemu-user-env: execve failed: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8**
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%13 = call i32 (...) @test()
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %5
%17 = load i8**, i8*** %6
%18 = load i32, i32* @stderr
%19 = call i32 @print_str_array(i32 %16, i8** %17, i32 %18)
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = call i8** @malloc(i32 8)
store i8** %22, i8*** %8
store i32 1, i32* %9
%23 = call i32 @load_nl_args_file(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32* %9, i8*** %8, i8** %10)
store i32 %23, i32* %11
%24 = load i32, i32* %11
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %3
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %3
%30 = load i8**, i8*** %6
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %8
%34 = getelementptr inbounds i8*, i8** %33, i64 0
store i8* %32, i8** %34
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* %9
%38 = load i8**, i8*** %8
%39 = load i32, i32* @stderr
%40 = call i32 @print_str_array(i32 %37, i8** %38, i32 %39)
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%43 = load i8**, i8*** %8
%44 = load i32, i32* %9
%45 = load i32, i32* %5
%46 = add nsw i32 %44, %45
%47 = sext i32 %46 to i64
%48 = mul i64 8, %47
%49 = trunc i64 %48 to i32
%50 = call i8** @realloc(i8** %43, i32 %49)
store i8** %50, i8*** %12
%51 = load i8**, i8*** %12
%52 = icmp ne i8** %51, null
br i1 %52, label %58, label %53
53: ; preds = %29
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %29
%59 = load i8**, i8*** %12
store i8** %59, i8*** %8
%60 = load i8**, i8*** %8
%61 = load i32, i32* %9
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %60, i64 %62
%64 = load i8**, i8*** %6
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i32, i32* %5
%67 = sub nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = mul i64 8, %68
%70 = trunc i64 %69 to i32
%71 = call i32 @memcpy(i8** %63, i8** %65, i32 %70)
%72 = load i8**, i8*** %8
%73 = load i32, i32* %5
%74 = load i32, i32* %9
%75 = add nsw i32 %73, %74
%76 = sub nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8*, i8** %72, i64 %77
store i8* null, i8** %78
%79 = load i8**, i8*** %8
%80 = load i8**, i8*** %7
%81 = call i32 @execve(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8** %79, i8** %80)
store i32 %81, i32* %11
%82 = load i32, i32* %11
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %89
84: ; preds = %58
%85 = load i32, i32* @stderr
%86 = load i32, i32* @errno
%87 = call i8* @strerror(i32 %86)
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %87)
br label %89
89: ; preds = %84, %58
%90 = load i32, i32* %11
ret i32 %90
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [4 x i8] c"m: \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [19 x i8] c"/etc/qemu-user-env\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"e: \00"
@.str.4 = [25 x i8] c"realloc for args failed\0A\00"
@.str.5 = [30 x i8] c"/usr/bin/qemu-ppc-static.real\00"
@.str.6 = [34 x i8] c"qemu-user-env: execve failed: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
%7 = tail call i32 (...) @test()
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = tail call i32 @print_str_array(i32 %0, i8** %1, i32 %10)
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = bitcast i8*** %4 to i8*
%15 = tail call i8** @malloc(i32 8)
store i8** %15, i8*** %4
%16 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%17 = bitcast i8** %6 to i8*
%18 = call i32 @load_nl_args_file(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32* %5, i8*** %4, i8** %6)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %3
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %3
%24 = load i8*, i8** %1
%25 = load i8**, i8*** %4
store i8* %24, i8** %25
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* %5
%29 = load i8**, i8*** %4
%30 = load i32, i32* @stderr
%31 = call i32 @print_str_array(i32 %28, i8** %29, i32 %30)
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%34 = load i8**, i8*** %4
%35 = load i32, i32* %5
%36 = add nsw i32 %35, %0
%37 = shl i32 %36, 3
%38 = call i8** @realloc(i8** %34, i32 %37)
%39 = icmp eq i8** %38, null
br i1 %39, label %40, label %45
40: ; preds = %23
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %23
store i8** %38, i8*** %4
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %38, i64 %47
%49 = getelementptr inbounds i8*, i8** %1, i64 1
%50 = shl i32 %0, 3
%51 = add i32 %50, -8
%52 = call i32 @memcpy(i8** %48, i8** %49, i32 %51)
%53 = load i8**, i8*** %4
%54 = load i32, i32* %5
%55 = add i32 %0, -1
%56 = add i32 %55, %54
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %53, i64 %57
store i8* null, i8** %58
%59 = load i8**, i8*** %4
%60 = call i32 @execve(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8** %59, i8** %2)
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %45
%63 = load i32, i32* @stderr
%64 = load i32, i32* @errno
%65 = call i8* @strerror(i32 %64)
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %65)
br label %67
67: ; preds = %62, %45
ret i32 %60
}