#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int _pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *_popen(char *, char *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int main(int argc, char *argv[]) {
  FILE *cmd_stdout;
  char cmd[64000];
  char buffer[42];
  char *fgets_result;
  int eof = 0;
  int pclose_result;
  int i;
  int result = 0;
  strcat(cmd, "\0");
  strcat(cmd, "openscad.exe");
  for (i = 1; i < argc; ++i) {
    strcat(cmd, " ");
    strcat(cmd, argv[i]);
  }
  strcat(cmd, " ");
  strcat(cmd, " 2>&1");
  cmd_stdout = _popen(cmd, "rt");
  if (cmd_stdout == NULL) {
    printf("Error opening _popen for command: %s", cmd);
    perror("Error message:");
    return 1;
  }
  while (!eof) {
    fgets_result = fgets(buffer, 42, cmd_stdout);
    if (fgets_result == NULL) {
      if (ferror(cmd_stdout)) {
        printf("Error reading from stdout of %s\n", cmd);
        result = 1;
      }
      if (feof(cmd_stdout)) {
        eof = 1;
      }
    } else {
      fprintf(stdout, "%s", buffer);
    }
  }
  pclose_result = _pclose(cmd_stdout);
  if (pclose_result < 0) {
    perror("Error while closing stdout for command:");
    result = 1;
  }
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfa70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xfa5c(%rbp)
movl   $0x0,-0xfa68(%rbp)
lea    -0xfa20(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0xfa20(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   10b0 <strcat@plt>
movl   $0x1,-0xfa64(%rbp)
mov    -0xfa64(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    123e <main+0xae>
lea    -0xfa20(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0xfa20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0xfa64(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   10b0 <strcat@plt>
mov    -0xfa64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfa64(%rbp)
jmp    11ed <main+0x5d>
lea    -0xfa20(%rbp),%rdi
lea    0xdc3(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0xfa20(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0xfa20(%rbp),%rdi
lea    0xda5(%rip),%rsi
call   1080 <_popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12b1 <main+0x121>
lea    -0xfa20(%rbp),%rsi
lea    0xd86(%rip),%rdi
call   1040 <printf@plt>
lea    0xd9f(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a7 <main+0x217>
jmp    12b6 <main+0x126>
cmpl   $0x0,-0xfa5c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12cf <main+0x13f>
jmp    136c <main+0x1dc>
lea    -0xfa50(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x2a,%esi
call   1050 <fgets@plt>
mov    %rax,-0xfa58(%rbp)
cmpq   $0x0,-0xfa58(%rbp)
jne    134b <main+0x1bb>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1329 <main+0x199>
lea    -0xfa20(%rbp),%rsi
lea    0xd34(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0xfa68(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1346 <main+0x1b6>
movl   $0x1,-0xfa5c(%rbp)
jmp    1367 <main+0x1d7>
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
lea    -0xfa50(%rbp),%rdx
lea    0xcda(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12b6 <main+0x126>
mov    -0x18(%rbp),%rdi
call   1090 <_pclose@plt>
mov    %eax,-0xfa60(%rbp)
cmpl   $0x0,-0xfa60(%rbp)
jge    139e <main+0x20e>
lea    0xce0(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0xfa68(%rbp)
mov    -0xfa68(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xfa70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xfa38,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
lea    0xe53(%rip),%rsi
lea    0x30(%rsp),%r14
mov    %r14,%rdi
call   10b0 <strcat@plt>
lea    0xe41(%rip),%rsi
mov    %r14,%rdi
call   10b0 <strcat@plt>
cmp    $0x2,%ebp
jl     1210 <main+0x80>
mov    %ebp,%r12d
mov    $0x1,%ebx
lea    0xe32(%rip),%r14
lea    0x30(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r14,%rsi
call   10b0 <strcat@plt>
mov    (%r15,%rbx,8),%rsi
mov    %rbp,%rdi
call   10b0 <strcat@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11f0 <main+0x60>
lea    0xdf8(%rip),%rsi
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <strcat@plt>
lea    0xde6(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
lea    0xddd(%rip),%rsi
mov    %rbx,%rdi
call   1080 <_popen@plt>
test   %rax,%rax
je     12f0 <main+0x160>
mov    %rax,%rbx
xor    %r14d,%r14d
mov    %rsp,%rbp
lea    0x30(%rsp),%r12
mov    0x2d80(%rip),%r15
lea    0xdd5(%rip),%r13
jmp    1284 <main+0xf4>
nopl   0x0(%rax)
mov    (%r15),%edi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1060 <fprintf@plt>
xor    %ecx,%ecx
test   %ecx,%ecx
jne    12cf <main+0x13f>
mov    %rbp,%rdi
mov    $0x2a,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1270 <main+0xe0>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     12bb <main+0x12b>
lea    0xda1(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1070 <feof@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
test   %ecx,%ecx
je     1284 <main+0xf4>
mov    %rbx,%rdi
call   1090 <_pclose@plt>
test   %eax,%eax
js     130a <main+0x17a>
mov    %r14d,%eax
add    $0xfa38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd23(%rip),%rdi
lea    0x30(%rsp),%rsi
call   1040 <printf@plt>
lea    0xd37(%rip),%rdi
jmp    1311 <main+0x181>
lea    0xd5e(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%r14d
jmp    12db <main+0x14b>

LLVM IR (-O0):
@.str = [2 x i8] zeroinitializer
@.str.1 = [13 x i8] c"openscad.exe\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [6 x i8] c" 2>&1\00"
@.str.4 = [3 x i8] c"rt\00"
@.str.5 = [37 x i8] c"Error opening _popen for command: %s\00"
@.str.6 = [15 x i8] c"Error message:\00"
@.str.7 = [33 x i8] c"Error reading from stdout of %s\0A\00"
@stdout = global i32 0
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [40 x i8] c"Error while closing stdout for command:\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [64000 x i8]
%8 = alloca [42 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
store i32 0, i32* %13
%14 = getelementptr inbounds [64000 x i8], [64000 x i8]* %7, i64 0, i64 0
%15 = call i32 @strcat(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds [64000 x i8], [64000 x i8]* %7, i64 0, i64 0
%17 = call i32 @strcat(i8* %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %12
br label %18
18: ; preds = %32, %2
%19 = load i32, i32* %12
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %35
22: ; preds = %18
%23 = getelementptr inbounds [64000 x i8], [64000 x i8]* %7, i64 0, i64 0
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = getelementptr inbounds [64000 x i8], [64000 x i8]* %7, i64 0, i64 0
%26 = load i8**, i8*** %5
%27 = load i32, i32* %12
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 @strcat(i8* %25, i8* %30)
br label %32
32: ; preds = %22
%33 = load i32, i32* %12
%34 = add nsw i32 %33, 1
store i32 %34, i32* %12
br label %18
35: ; preds = %18
%36 = getelementptr inbounds [64000 x i8], [64000 x i8]* %7, i64 0, i64 0
%37 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%38 = getelementptr inbounds [64000 x i8], [64000 x i8]* %7, i64 0, i64 0
%39 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%40 = getelementptr inbounds [64000 x i8], [64000 x i8]* %7, i64 0, i64 0
%41 = call i32* @_popen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %41, i32** %6
%42 = load i32*, i32** %6
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %48
44: ; preds = %35
%45 = getelementptr inbounds [64000 x i8], [64000 x i8]* %7, i64 0, i64 0
%46 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %45)
%47 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %86
48: ; preds = %35
br label %49
49: ; preds = %76, %48
%50 = load i32, i32* %10
%51 = icmp ne i32 %50, 0
%52 = xor i1 %51, true
br i1 %52, label %53, label %77
53: ; preds = %49
%54 = getelementptr inbounds [42 x i8], [42 x i8]* %8, i64 0, i64 0
%55 = load i32*, i32** %6
%56 = call i8* @fgets(i8* %54, i32 42, i32* %55)
store i8* %56, i8** %9
%57 = load i8*, i8** %9
%58 = icmp eq i8* %57, null
br i1 %58, label %59, label %72
59: ; preds = %53
%60 = load i32*, i32** %6
%61 = call i64 @ferror(i32* %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = getelementptr inbounds [64000 x i8], [64000 x i8]* %7, i64 0, i64 0
%65 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i8* %64)
store i32 1, i32* %13
br label %66
66: ; preds = %63, %59
%67 = load i32*, i32** %6
%68 = call i64 @feof(i32* %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %66
store i32 1, i32* %10
br label %71
71: ; preds = %70, %66
br label %76
72: ; preds = %53
%73 = load i32, i32* @stdout
%74 = getelementptr inbounds [42 x i8], [42 x i8]* %8, i64 0, i64 0
%75 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %72, %71
br label %49
77: ; preds = %49
%78 = load i32*, i32** %6
%79 = call i32 @_pclose(i32* %78)
store i32 %79, i32* %11
%80 = load i32, i32* %11
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %77
%83 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %13
br label %84
84: ; preds = %82, %77
%85 = load i32, i32* %13
store i32 %85, i32* %3
br label %86
86: ; preds = %84, %44
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str = [2 x i8] zeroinitializer
@.str.1 = [13 x i8] c"openscad.exe\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [6 x i8] c" 2>&1\00"
@.str.4 = [3 x i8] c"rt\00"
@.str.5 = [37 x i8] c"Error opening _popen for command: %s\00"
@.str.6 = [15 x i8] c"Error message:\00"
@.str.7 = [33 x i8] c"Error reading from stdout of %s\0A\00"
@stdout = global i32 0
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [40 x i8] c"Error while closing stdout for command:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [64000 x i8]
%4 = alloca [42 x i8]
%5 = getelementptr inbounds [64000 x i8], [64000 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [42 x i8], [42 x i8]* %4, i64 0, i64 0
%7 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %20
10: ; preds = %2
%11 = zext i32 %0 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 1, %10 ], [ %18, %12 ]
%14 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = getelementptr inbounds i8*, i8** %1, i64 %13
%16 = load i8*, i8** %15
%17 = call i32 @strcat(i8* %5, i8* %16)
%18 = add nuw nsw i64 %13, 1
%19 = icmp eq i64 %18, %11
br i1 %19, label %20, label %12
20: ; preds = %12, %2
%21 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32* @_popen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %5)
br label %51
27: ; preds = %20, %44
%28 = phi i32 [ %46, %44 ], [ 0, %20 ]
%29 = call i8* @fgets(i8* %6, i32 42, i32* %23)
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %41
31: ; preds = %27
%32 = call i64 @ferror(i32* %23)
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i8* %5)
br label %36
36: ; preds = %34, %31
%37 = phi i32 [ 1, %34 ], [ %28, %31 ]
%38 = call i64 @feof(i32* %23)
%39 = icmp ne i64 %38, 0
%40 = zext i1 %39 to i32
br label %44
41: ; preds = %27
%42 = load i32, i32* @stdout
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %6)
br label %44
44: ; preds = %36, %41
%45 = phi i32 [ 0, %41 ], [ %40, %36 ]
%46 = phi i32 [ %28, %41 ], [ %37, %36 ]
%47 = icmp eq i32 %45, 0
br i1 %47, label %27, label %48
48: ; preds = %44
%49 = call i32 @_pclose(i32* %23)
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48, %25
%52 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), %25 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0), %48 ]
%53 = call i32 @perror(i8* %52)
br label %54
54: ; preds = %51, %48
%55 = phi i32 [ %46, %48 ], [ 1, %51 ]
ret i32 %55
}