#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*/ delete_quotes(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *getenv(char *);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int system(char *);
int main(int argc, char **argv) {
  char *mercury_config_dir;
  char *mercury_options;
  char set_debugger_init[8196];
  char set_mercury_options[8196];
  char command_string[8196];
  int command_string_pos;
  int arg_num;
  mercury_config_dir = getenv("MERCURY_CONFIG_DIR");
  if (mercury_config_dir == NULL) {
    fprintf(stderr, "MERCURY_CONFIG_DIR not set.\n");
    exit(EXIT_FAILURE);
  }
  delete_quotes(mercury_config_dir);
  sprintf(set_debugger_init, "MERCURY_DEBUGGER_INIT=%s\\mdb\\mdbrc",
          mercury_config_dir);
  putenv(set_debugger_init);
  mercury_options = getenv("MERCURY_OPTIONS");
  if (mercury_options == NULL) {
    mercury_options = "";
  }
  sprintf(set_mercury_options, "MERCURY_OPTIONS=-Di %s", mercury_options);
  putenv(set_mercury_options);
  command_string_pos = 0;
  for (arg_num = 1; argv[arg_num] != NULL; arg_num++) {
    strcpy(&command_string[command_string_pos], argv[arg_num]);
    command_string_pos += strlen(argv[arg_num]);
    strcpy(&command_string[command_string_pos], " ");
    command_string_pos++;
  }
  command_string[command_string_pos] = '\0';
  return system(command_string);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x6060,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe50(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e7 <main+0x57>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1070 <delete_quotes@plt>
lea    -0x2030(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe2e(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x2030(%rbp),%rdi
call   1080 <putenv@plt>
lea    0xe39(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1239 <main+0xa9>
lea    0xdfa(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    -0x4040(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe18(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x4040(%rbp),%rdi
call   1080 <putenv@plt>
movl   $0x0,-0x6054(%rbp)
movl   $0x1,-0x6058(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x6058(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1312 <main+0x182>
movslq -0x6054(%rbp),%rax
lea    -0x6050(%rbp),%rdi
add    %rax,%rdi
mov    -0x10(%rbp),%rax
movslq -0x6058(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x6058(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
movslq -0x6054(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x6054(%rbp)
movslq -0x6054(%rbp),%rax
lea    -0x6050(%rbp),%rdi
add    %rax,%rdi
lea    0xd90(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x6054(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6054(%rbp)
mov    -0x6058(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6058(%rbp)
jmp    1270 <main+0xe0>
movslq -0x6054(%rbp),%rax
movb   $0x0,-0x6050(%rbp,%rax,1)
lea    -0x6050(%rbp),%rdi
call   1060 <system@plt>
add    $0x6060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x6028,%rsp
mov    %rsi,%r12
lea    0xe58(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1297 <main+0x107>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <delete_quotes@plt>
lea    0xe68(%rip),%rsi
lea    0x4020(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rdx
call   10a0 <sprintf@plt>
mov    %r15,%rdi
call   1080 <putenv@plt>
lea    0xe69(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe36(%rip),%rdx
cmovne %rax,%rdx
lea    0xe5f(%rip),%rsi
lea    0x2010(%rsp),%r14
mov    %r14,%rdi
call   10a0 <sprintf@plt>
mov    %r14,%rdi
call   1080 <putenv@plt>
mov    0x8(%r12),%rsi
test   %rsi,%rsi
je     127a <main+0xea>
add    $0x10,%r12
xor    %ebx,%ebx
lea    0xe47(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%rsp,%rbx,1),%rdi
call   1040 <strcpy@plt>
mov    -0x8(%r12),%rdi
call   1050 <strlen@plt>
add    %rbx,%rax
movslq %eax,%rbx
lea    (%rsp,%rbx,1),%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
add    $0x1,%ebx
movslq %ebx,%rbx
mov    (%r12),%rsi
add    $0x8,%r12
test   %rsi,%rsi
jne    1240 <main+0xb0>
jmp    127c <main+0xec>
xor    %ebx,%ebx
movb   $0x0,(%rsp,%rbx,1)
mov    %rsp,%rdi
call   1060 <system@plt>
add    $0x6028,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    0xd6c(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"MERCURY_CONFIG_DIR\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"MERCURY_CONFIG_DIR not set.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [35 x i8] c"MERCURY_DEBUGGER_INIT=%s\\mdb\\mdbrc\00"
@.str.3 = [16 x i8] c"MERCURY_OPTIONS\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [23 x i8] c"MERCURY_OPTIONS=-Di %s\00"
@.str.6 = [2 x i8] c" \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [8196 x i8]
%9 = alloca [8196 x i8]
%10 = alloca [8196 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i8* @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8*, i8** %6
%23 = call i32 @delete_quotes(i8* %22)
%24 = getelementptr inbounds [8196 x i8], [8196 x i8]* %8, i64 0, i64 0
%25 = load i8*, i8** %6
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds [8196 x i8], [8196 x i8]* %8, i64 0, i64 0
%28 = call i32 @putenv(i8* %27)
%29 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %33
32: ; preds = %21
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8** %7
br label %33
33: ; preds = %32, %21
%34 = getelementptr inbounds [8196 x i8], [8196 x i8]* %9, i64 0, i64 0
%35 = load i8*, i8** %7
%36 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds [8196 x i8], [8196 x i8]* %9, i64 0, i64 0
%38 = call i32 @putenv(i8* %37)
store i32 0, i32* %11
store i32 1, i32* %12
br label %39
39: ; preds = %72, %33
%40 = load i8**, i8*** %5
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %75
46: ; preds = %39
%47 = load i32, i32* %11
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [8196 x i8], [8196 x i8]* %10, i64 0, i64 %48
%50 = load i8**, i8*** %5
%51 = load i32, i32* %12
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
%54 = load i8*, i8** %53
%55 = call i32 @strcpy(i8* %49, i8* %54)
%56 = load i8**, i8*** %5
%57 = load i32, i32* %12
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %56, i64 %58
%60 = load i8*, i8** %59
%61 = call i64 @strlen(i8* %60)
%62 = load i32, i32* %11
%63 = sext i32 %62 to i64
%64 = add nsw i64 %63, %61
%65 = trunc i64 %64 to i32
store i32 %65, i32* %11
%66 = load i32, i32* %11
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [8196 x i8], [8196 x i8]* %10, i64 0, i64 %67
%69 = call i32 @strcpy(i8* %68, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%70 = load i32, i32* %11
%71 = add nsw i32 %70, 1
store i32 %71, i32* %11
br label %72
72: ; preds = %46
%73 = load i32, i32* %12
%74 = add nsw i32 %73, 1
store i32 %74, i32* %12
br label %39
75: ; preds = %39
%76 = load i32, i32* %11
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [8196 x i8], [8196 x i8]* %10, i64 0, i64 %77
store i8 0, i8* %78
%79 = getelementptr inbounds [8196 x i8], [8196 x i8]* %10, i64 0, i64 0
%80 = call i32 @system(i8* %79)
ret i32 %80
}

LLVM IR (-O2):
@.str = [19 x i8] c"MERCURY_CONFIG_DIR\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"MERCURY_CONFIG_DIR not set.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [35 x i8] c"MERCURY_DEBUGGER_INIT=%s\\mdb\\mdbrc\00"
@.str.3 = [16 x i8] c"MERCURY_OPTIONS\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [23 x i8] c"MERCURY_OPTIONS=-Di %s\00"
@.str.6 = [2 x i8] c" \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [8196 x i8]
%4 = alloca [8196 x i8]
%5 = alloca [8196 x i8]
%6 = getelementptr inbounds [8196 x i8], [8196 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [8196 x i8], [8196 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [8196 x i8], [8196 x i8]* %5, i64 0, i64 0
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = tail call i32 @delete_quotes(i8* %9)
%18 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%19 = call i32 @putenv(i8* %6)
%20 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i8* %20, null
%22 = select i1 %21, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* %20
%23 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %22)
%24 = call i32 @putenv(i8* %7)
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = icmp eq i8* %26, null
br i1 %27, label %48, label %28
28: ; preds = %16, %28
%29 = phi i64 [ %42, %28 ], [ 1, %16 ]
%30 = phi i8* [ %46, %28 ], [ %26, %16 ]
%31 = phi i8** [ %45, %28 ], [ %25, %16 ]
%32 = phi i64 [ %44, %28 ], [ 0, %16 ]
%33 = getelementptr inbounds [8196 x i8], [8196 x i8]* %5, i64 0, i64 %32
%34 = call i32 @strcpy(i8* %33, i8* %30)
%35 = load i8*, i8** %31
%36 = call i64 @strlen(i8* dereferenceable(1) %35)
%37 = add nsw i64 %36, %32
%38 = shl i64 %37, 32
%39 = ashr exact i64 %38, 32
%40 = getelementptr inbounds [8196 x i8], [8196 x i8]* %5, i64 0, i64 %39
%41 = call i32 @strcpy(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%42 = add nuw i64 %29, 1
%43 = add i64 %38, 4294967296
%44 = ashr exact i64 %43, 32
%45 = getelementptr inbounds i8*, i8** %1, i64 %42
%46 = load i8*, i8** %45
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %28
48: ; preds = %28, %16
%49 = phi i64 [ 0, %16 ], [ %44, %28 ]
%50 = getelementptr inbounds [8196 x i8], [8196 x i8]* %5, i64 0, i64 %49
store i8 0, i8* %50
%51 = call i32 @system(i8* %8)
ret i32 %51
}