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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
scalar_t__ strstr(char *, char *);
int check_gcc_reject_mno_cygwin(const char *gcc_path) {
  FILE *fp;
  char tmp[1024];
  const char *p;
  int ver;
  snprintf(tmp, sizeof(tmp), "%s -mno-cygwin 2>&1", gcc_path);
  fp = popen(tmp, "r");
  if (fp == NULL) {
    printf("Error: failed to run gcc\n");
    return -1;
  }
  while (fgets(tmp, sizeof(tmp), fp) != NULL) {
    if (strstr(tmp, "unrecognized") && strstr(tmp, "-mno-cygwin"))
      return 1;
  }
  pclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<check_gcc_reject_mno_cygwin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x400,%esi
lea    0xe7a(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c5 <check_gcc_reject_mno_cygwin+0x65>
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1244 <check_gcc_reject_mno_cygwin+0xe4>
jmp    11ca <check_gcc_reject_mno_cygwin+0x6a>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1234 <check_gcc_reject_mno_cygwin+0xd4>
lea    -0x420(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     122f <check_gcc_reject_mno_cygwin+0xcf>
lea    -0x420(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     122f <check_gcc_reject_mno_cygwin+0xcf>
movl   $0x1,-0x4(%rbp)
jmp    1244 <check_gcc_reject_mno_cygwin+0xe4>
jmp    11ca <check_gcc_reject_mno_cygwin+0x6a>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_gcc_reject_mno_cygwin>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rcx
lea    0xe88(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1050 <snprintf@plt>
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
call   1070 <popen@plt>
test   %rax,%rax
je     1218 <check_gcc_reject_mno_cygwin+0xb8>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     120c <check_gcc_reject_mno_cygwin+0xac>
lea    0xe5b(%rip),%r14
mov    %rsp,%rbx
lea    0xe5e(%rip),%r12
jmp    11e5 <check_gcc_reject_mno_cygwin+0x85>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     120c <check_gcc_reject_mno_cygwin+0xac>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11d0 <check_gcc_reject_mno_cygwin+0x70>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11d0 <check_gcc_reject_mno_cygwin+0x70>
mov    $0x1,%eax
jmp    1229 <check_gcc_reject_mno_cygwin+0xc9>
mov    %r15,%rdi
call   1040 <pclose@plt>
xor    %eax,%eax
jmp    1229 <check_gcc_reject_mno_cygwin+0xc9>
lea    0xe10(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"%s -mno-cygwin 2>&1\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Error: failed to run gcc\0A\00"
@.str.3 = [13 x i8] c"unrecognized\00"
@.str.4 = [12 x i8] c"-mno-cygwin\00"
define i32 @check_gcc_reject_mno_cygwin(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i32 @snprintf(i8* %8, i32 1024, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = call i32* @popen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %4
%13 = load i32*, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %36
17: ; preds = %1
br label %18
18: ; preds = %32, %17
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%20 = load i32*, i32** %4
%21 = call i32* @fgets(i8* %19, i32 1024, i32* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %33
23: ; preds = %18
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%25 = call i64 @strstr(i8* %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%29 = call i64 @strstr(i8* %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 1, i32* %2
br label %36
32: ; preds = %27, %23
br label %18
33: ; preds = %18
%34 = load i32*, i32** %4
%35 = call i32 @pclose(i32* %34)
store i32 0, i32* %2
br label %36
36: ; preds = %33, %31, %15
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@.str = [20 x i8] c"%s -mno-cygwin 2>&1\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [13 x i8] c"unrecognized\00"
@.str.4 = [12 x i8] c"-mno-cygwin\00"
@str = [25 x i8] c"Error: failed to run gcc\00"
define i32 @check_gcc_reject_mno_cygwin(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 1024, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = call i32* @fgets(i8* %3, i32 1024, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %21, label %12
10: ; preds = %1
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %23
12: ; preds = %7, %18
%13 = call i64 @strstr(i8* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = call i64 @strstr(i8* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15, %12
%19 = call i32* @fgets(i8* %3, i32 1024, i32* %5)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %12
21: ; preds = %18, %7
%22 = call i32 @pclose(i32* %5)
br label %23
23: ; preds = %15, %21, %10
%24 = phi i32 [ -1, %10 ], [ 0, %21 ], [ 1, %15 ]
ret i32 %24
}