#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int system(char *);
int test_satisfiability(int nbv, int nbc, char *fname) {
  char *fname_pre = (char *)malloc((strlen(fname) + 5) * sizeof(char));
  memset(fname_pre, 0, (strlen(fname) + 5) * sizeof(char));
  sprintf(fname_pre, "pre_%s", fname);
  FILE *out = fopen(fname_pre, "w");
  fprintf(out, "p cnf %d %d\n", nbv, nbc);
  fprintf(stdout, "---- minisat query prefix: p cnf %d %d\n", nbv, nbc);
  fclose(out);
  free(fname_pre);
  char *command = (char *)malloc((100 + 3 * strlen(fname)) * sizeof(char));
  memset(command, 0, (100 + 3 * strlen(fname)) * sizeof(char));
  sprintf(command, "cat pre_%s %s 1> sat_%s", fname, fname, fname);
  if (system(command) != -1) {
    memset(command, 0, (100 + 3 * strlen(fname)) * sizeof(char));
    sprintf(command, "minisat -verb=0 sat_%s result.txt 1> msat_%s", fname,
            fname);
    if (system(command) != -1) {
      FILE *res;
      res = fopen("result.txt", "r");
      char *s = malloc(10 * sizeof(char));
      s[9] = '\0';
      fgets(s, 10, res);
      fclose(res);
      if (strcmp(s, "UNSAT\n") == 0) {
        free(command);
        free(s);
        return 0;
      }
      free(s);
    }
  }
  free(command);
  return 1;
}


x86 assembly (clang, -O0):
<test_satisfiability>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x5,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
add    $0x5,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xde0(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xde3(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xdac(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
imul   $0x3,%eax,%eax
add    $0x64,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
imul   $0x3,%eax,%eax
add    $0x64,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xd5c(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
call   1060 <system@plt>
cmp    $0xffffffff,%eax
je     13d2 <test_satisfiability+0x222>
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x58(%rbp),%rdi
imul   $0x3,%eax,%eax
add    $0x64,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xd1e(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
call   1060 <system@plt>
cmp    $0xffffffff,%eax
je     13cd <test_satisfiability+0x21d>
lea    0xd2b(%rip),%rdi
lea    0xd2f(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    $0xa,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movb   $0x0,0x9(%rax)
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0xa,%esi
call   1080 <fgets@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x40(%rbp),%rdi
lea    0xcec(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    13c4 <test_satisfiability+0x214>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    13e2 <test_satisfiability+0x232>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
jmp    13d2 <test_satisfiability+0x222>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_satisfiability>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%r15d
mov    %rdx,%rdi
call   1050 <strlen@plt>
lea    0x5(%rax),%edi
call   10b0 <malloc@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x5(%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
lea    0xe10(%rip),%rsi
mov    %r12,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   10d0 <sprintf@plt>
lea    0xe03(%rip),%rsi
mov    %r12,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbp
lea    0xe0e(%rip),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
mov    %r14d,%ecx
call   10a0 <fprintf@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%rdi
lea    0xdd4(%rip),%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
call   10a0 <fprintf@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    (%rax,%rax,2),%edi
add    $0x64,%edi
call   10b0 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    (%rax,%rax,2),%edx
add    $0x64,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
lea    0xdac(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %rbx,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   10d0 <sprintf@plt>
mov    %r14,%rdi
call   1060 <system@plt>
cmp    $0xffffffff,%eax
je     1340 <test_satisfiability+0x190>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    (%rax,%rax,2),%edx
add    $0x64,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
lea    0xd81(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   10d0 <sprintf@plt>
mov    %r14,%rdi
call   1060 <system@plt>
cmp    $0xffffffff,%eax
je     1340 <test_satisfiability+0x190>
lea    0xd8a(%rip),%rdi
lea    0xd8e(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbp
mov    $0xa,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,0x9(%rax)
mov    %rax,%rdi
mov    $0xa,%esi
mov    %rbp,%rdx
call   1080 <fgets@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xd58(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1356 <test_satisfiability+0x1a6>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    134d <test_satisfiability+0x19d>

LLVM IR (-O0):
@.str = [7 x i8] c"pre_%s\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [13 x i8] c"p cnf %d %d\0A\00"
@stdout = global i32* null
@.str.3 = [40 x i8] c"---- minisat query prefix: p cnf %d %d\0A\00"
@.str.4 = [24 x i8] c"cat pre_%s %s 1> sat_%s\00"
@.str.5 = [45 x i8] c"minisat -verb=0 sat_%s result.txt 1> msat_%s\00"
@.str.6 = [11 x i8] c"result.txt\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [7 x i8] c"UNSAT\0A\00"
define i32 @test_satisfiability(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%13 = load i8*, i8** %7
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %14, 5
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 1
%18 = trunc i64 %17 to i32
%19 = call i8* @malloc(i32 %18)
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = load i8*, i8** %7
%22 = call i32 @strlen(i8* %21)
%23 = add nsw i32 %22, 5
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 1
%26 = trunc i64 %25 to i32
%27 = call i32 @memset(i8* %20, i32 0, i32 %26)
%28 = load i8*, i8** %8
%29 = load i8*, i8** %7
%30 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %8
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %9
%33 = load i32*, i32** %9
%34 = load i32, i32* %5
%35 = load i32, i32* %6
%36 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %34, i32 %35)
%37 = load i32*, i32** @stdout
%38 = load i32, i32* %5
%39 = load i32, i32* %6
%40 = call i32 @fprintf(i32* %37, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %38, i32 %39)
%41 = load i32*, i32** %9
%42 = call i32 @fclose(i32* %41)
%43 = load i8*, i8** %8
%44 = call i32 @free(i8* %43)
%45 = load i8*, i8** %7
%46 = call i32 @strlen(i8* %45)
%47 = mul nsw i32 3, %46
%48 = add nsw i32 100, %47
%49 = sext i32 %48 to i64
%50 = mul i64 %49, 1
%51 = trunc i64 %50 to i32
%52 = call i8* @malloc(i32 %51)
store i8* %52, i8** %10
%53 = load i8*, i8** %10
%54 = load i8*, i8** %7
%55 = call i32 @strlen(i8* %54)
%56 = mul nsw i32 3, %55
%57 = add nsw i32 100, %56
%58 = sext i32 %57 to i64
%59 = mul i64 %58, 1
%60 = trunc i64 %59 to i32
%61 = call i32 @memset(i8* %53, i32 0, i32 %60)
%62 = load i8*, i8** %10
%63 = load i8*, i8** %7
%64 = load i8*, i8** %7
%65 = load i8*, i8** %7
%66 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %62, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %63, i8* %64, i8* %65)
%67 = load i8*, i8** %10
%68 = call i32 @system(i8* %67)
%69 = icmp ne i32 %68, -1
br i1 %69, label %70, label %109
70: ; preds = %3
%71 = load i8*, i8** %10
%72 = load i8*, i8** %7
%73 = call i32 @strlen(i8* %72)
%74 = mul nsw i32 3, %73
%75 = add nsw i32 100, %74
%76 = sext i32 %75 to i64
%77 = mul i64 %76, 1
%78 = trunc i64 %77 to i32
%79 = call i32 @memset(i8* %71, i32 0, i32 %78)
%80 = load i8*, i8** %10
%81 = load i8*, i8** %7
%82 = load i8*, i8** %7
%83 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %80, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i8* %81, i8* %82)
%84 = load i8*, i8** %10
%85 = call i32 @system(i8* %84)
%86 = icmp ne i32 %85, -1
br i1 %86, label %87, label %108
87: ; preds = %70
%88 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %88, i32** %11
%89 = call i8* @malloc(i32 10)
store i8* %89, i8** %12
%90 = load i8*, i8** %12
%91 = getelementptr inbounds i8, i8* %90, i64 9
store i8 0, i8* %91
%92 = load i8*, i8** %12
%93 = load i32*, i32** %11
%94 = call i32 @fgets(i8* %92, i32 10, i32* %93)
%95 = load i32*, i32** %11
%96 = call i32 @fclose(i32* %95)
%97 = load i8*, i8** %12
%98 = call i64 @strcmp(i8* %97, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%99 = icmp eq i64 %98, 0
br i1 %99, label %100, label %105
100: ; preds = %87
%101 = load i8*, i8** %10
%102 = call i32 @free(i8* %101)
%103 = load i8*, i8** %12
%104 = call i32 @free(i8* %103)
store i32 0, i32* %4
br label %112
105: ; preds = %87
%106 = load i8*, i8** %12
%107 = call i32 @free(i8* %106)
br label %108
108: ; preds = %105, %70
br label %109
109: ; preds = %108, %3
%110 = load i8*, i8** %10
%111 = call i32 @free(i8* %110)
store i32 1, i32* %4
br label %112
112: ; preds = %109, %100
%113 = load i32, i32* %4
ret i32 %113
}

LLVM IR (-O2):
@.str = [7 x i8] c"pre_%s\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [13 x i8] c"p cnf %d %d\0A\00"
@stdout = global i32* null
@.str.3 = [40 x i8] c"---- minisat query prefix: p cnf %d %d\0A\00"
@.str.4 = [24 x i8] c"cat pre_%s %s 1> sat_%s\00"
@.str.5 = [45 x i8] c"minisat -verb=0 sat_%s result.txt 1> msat_%s\00"
@.str.6 = [11 x i8] c"result.txt\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [7 x i8] c"UNSAT\0A\00"
define i32 @test_satisfiability(i32 %0, i32 %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = add nsw i32 %4, 5
%6 = tail call i8* @malloc(i32 %5)
%7 = tail call i32 @strlen(i8* %2)
%8 = add nsw i32 %7, 5
%9 = tail call i32 @memset(i8* %6, i32 0, i32 %8)
%10 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %2)
%11 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %1)
%13 = load i32*, i32** @stdout
%14 = tail call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %0, i32 %1)
%15 = tail call i32 @fclose(i32* %11)
%16 = tail call i32 @free(i8* %6)
%17 = tail call i32 @strlen(i8* %2)
%18 = mul nsw i32 %17, 3
%19 = add nsw i32 %18, 100
%20 = tail call i8* @malloc(i32 %19)
%21 = tail call i32 @strlen(i8* %2)
%22 = mul nsw i32 %21, 3
%23 = add nsw i32 %22, 100
%24 = tail call i32 @memset(i8* %20, i32 0, i32 %23)
%25 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %20, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %2, i8* %2, i8* %2)
%26 = tail call i32 @system(i8* %20)
%27 = icmp eq i32 %26, -1
br i1 %27, label %49, label %28
28: ; preds = %3
%29 = tail call i32 @strlen(i8* %2)
%30 = mul nsw i32 %29, 3
%31 = add nsw i32 %30, 100
%32 = tail call i32 @memset(i8* %20, i32 0, i32 %31)
%33 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %20, i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i8* %2, i8* %2)
%34 = tail call i32 @system(i8* %20)
%35 = icmp eq i32 %34, -1
br i1 %35, label %49, label %36
36: ; preds = %28
%37 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%38 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%39 = getelementptr inbounds i8, i8* %38, i64 9
store i8 0, i8* %39
%40 = tail call i32 @fgets(i8* %38, i32 10, i32* %37)
%41 = tail call i32 @fclose(i32* %37)
%42 = tail call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %36
%45 = tail call i32 @free(i8* %20)
%46 = tail call i32 @free(i8* %38)
br label %51
47: ; preds = %36
%48 = tail call i32 @free(i8* %38)
br label %49
49: ; preds = %47, %28, %3
%50 = tail call i32 @free(i8* %20)
br label %51
51: ; preds = %44, %49
%52 = phi i32 [ 1, %49 ], [ 0, %44 ]
ret i32 %52
}