#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 atoi(char *);
int /*<<< orphan*/ free(int *);
int getNumClauses(int);
int /*<<< orphan*/ getRandomEquAndSol(int *, int *, int, int);
int *malloc(int);
int /*<<< orphan*/ printEquation(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ saveEquation(char *, int *, int);
int /*<<< orphan*/ saveSolution(char *, int *, int);
int /*<<< orphan*/ srand(int);
int mainPrivate(int narg, char *varg[]) {
  if (narg < 3 || narg > 6) {
    printf("ERROR: call as ./3SATGenerator seed "
           "numBools[, printEqu][, equFN][, solFN]\n");
    return 1;
  }
  int rSeed = atoi(varg[1]);
  int numBools = atoi(varg[2]);
  int printFlag = (narg >= 3 + 1) ? atoi(varg[3]) : 1;
  int equFNPassed = (narg >= 4 + 1);
  int solFNPassed = (narg == 5 + 1);
  srand(rSeed);
  int numClauses = getNumClauses(numBools);
  int *equ = malloc(numClauses * 3 * sizeof(int));
  int *sol = malloc(numBools * sizeof(int));
  getRandomEquAndSol(equ, sol, numBools, numClauses);
  if (equFNPassed)
    saveEquation(varg[4], equ, numClauses);
  if (printFlag)
    printEquation(equ, numClauses);
  if (solFNPassed)
    saveSolution(varg[5], sol, numBools);
  free(equ);
  free(sol);
  return 0;
}


x86 assembly (clang, -O0):
<mainPrivate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     11c3 <mainPrivate+0x23>
cmpl   $0x6,-0x8(%rbp)
jle    11db <mainPrivate+0x3b>
lea    0xe36(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1304 <mainPrivate+0x164>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     121a <mainPrivate+0x7a>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x3c(%rbp)
jmp    1227 <mainPrivate+0x87>
mov    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1227 <mainPrivate+0x87>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x5,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x6,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <srand@plt>
mov    -0x18(%rbp),%edi
call   1050 <getNumClauses@plt>
mov    %eax,-0x28(%rbp)
imul   $0x3,-0x28(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x28(%rbp),%ecx
call   1070 <getRandomEquAndSol@plt>
cmpl   $0x0,-0x20(%rbp)
je     12b7 <mainPrivate+0x117>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   10a0 <saveEquation@plt>
cmpl   $0x0,-0x1c(%rbp)
je     12cd <mainPrivate+0x12d>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1040 <printEquation@plt>
cmpl   $0x0,-0x24(%rbp)
je     12eb <mainPrivate+0x14b>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   10b0 <saveSolution@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mainPrivate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
lea    -0x7(%rbx),%eax
cmp    $0xfffffffb,%eax
ja     11cb <mainPrivate+0x2b>
lea    0xe44(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    128c <mainPrivate+0xec>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%r14),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r12d
mov    $0x1,%eax
cmp    $0x4,%ebx
jb     11f8 <mainPrivate+0x58>
mov    0x18(%r14),%rdi
call   10c0 <atoi@plt>
mov    %eax,0x4(%rsp)
mov    %ebp,%edi
call   1080 <srand@plt>
mov    %r12d,%edi
call   1060 <getNumClauses@plt>
mov    %eax,%r15d
lea    0x0(,%r15,4),%eax
lea    (%rax,%rax,2),%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    %r12d,%edi
shl    $0x2,%edi
call   1090 <malloc@plt>
mov    %rax,%r13
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1070 <getRandomEquAndSol@plt>
cmp    $0x5,%ebx
jb     1254 <mainPrivate+0xb4>
mov    0x20(%r14),%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
call   10a0 <saveEquation@plt>
cmpl   $0x0,0x4(%rsp)
je     1266 <mainPrivate+0xc6>
mov    %rbp,%rdi
mov    %r15d,%esi
call   1050 <printEquation@plt>
cmp    $0x6,%ebx
jne    127a <mainPrivate+0xda>
mov    0x28(%r14),%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   10b0 <saveSolution@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [76 x i8] c"ERROR: call as ./3SATGenerator seed numBools[, printEqu][, equFN][, solFN]\0A\00"
define i32 @mainPrivate(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %19, label %16
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 6
br i1 %18, label %19, label %21
19: ; preds = %16, %2
%20 = call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %97
21: ; preds = %16
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %6
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %7
%30 = load i32, i32* %4
%31 = icmp sge i32 %30, 4
br i1 %31, label %32, label %37
32: ; preds = %21
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 3
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
br label %38
37: ; preds = %21
br label %38
38: ; preds = %37, %32
%39 = phi i32 [ %36, %32 ], [ 1, %37 ]
store i32 %39, i32* %8
%40 = load i32, i32* %4
%41 = icmp sge i32 %40, 5
%42 = zext i1 %41 to i32
store i32 %42, i32* %9
%43 = load i32, i32* %4
%44 = icmp eq i32 %43, 6
%45 = zext i1 %44 to i32
store i32 %45, i32* %10
%46 = load i32, i32* %6
%47 = call i32 @srand(i32 %46)
%48 = load i32, i32* %7
%49 = call i32 @getNumClauses(i32 %48)
store i32 %49, i32* %11
%50 = load i32, i32* %11
%51 = mul nsw i32 %50, 3
%52 = sext i32 %51 to i64
%53 = mul i64 %52, 4
%54 = trunc i64 %53 to i32
%55 = call i32* @malloc(i32 %54)
store i32* %55, i32** %12
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = mul i64 %57, 4
%59 = trunc i64 %58 to i32
%60 = call i32* @malloc(i32 %59)
store i32* %60, i32** %13
%61 = load i32*, i32** %12
%62 = load i32*, i32** %13
%63 = load i32, i32* %7
%64 = load i32, i32* %11
%65 = call i32 @getRandomEquAndSol(i32* %61, i32* %62, i32 %63, i32 %64)
%66 = load i32, i32* %9
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %75
68: ; preds = %38
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 4
%71 = load i8*, i8** %70
%72 = load i32*, i32** %12
%73 = load i32, i32* %11
%74 = call i32 @saveEquation(i8* %71, i32* %72, i32 %73)
br label %75
75: ; preds = %68, %38
%76 = load i32, i32* %8
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %75
%79 = load i32*, i32** %12
%80 = load i32, i32* %11
%81 = call i32 @printEquation(i32* %79, i32 %80)
br label %82
82: ; preds = %78, %75
%83 = load i32, i32* %10
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %92
85: ; preds = %82
%86 = load i8**, i8*** %5
%87 = getelementptr inbounds i8*, i8** %86, i64 5
%88 = load i8*, i8** %87
%89 = load i32*, i32** %13
%90 = load i32, i32* %7
%91 = call i32 @saveSolution(i8* %88, i32* %89, i32 %90)
br label %92
92: ; preds = %85, %82
%93 = load i32*, i32** %12
%94 = call i32 @free(i32* %93)
%95 = load i32*, i32** %13
%96 = call i32 @free(i32* %95)
store i32 0, i32* %3
br label %97
97: ; preds = %92, %19
%98 = load i32, i32* %3
ret i32 %98
}

LLVM IR (-O2):
@str = [75 x i8] c"ERROR: call as ./3SATGenerator seed numBools[, printEqu][, equFN][, solFN]\00"
define i32 @mainPrivate(i32 %0, i8** nocapture %1) {
%3 = add i32 %0, -7
%4 = icmp ult i32 %3, -4
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str, i64 0, i64 0))
br label %46
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = icmp ugt i32 %0, 3
br i1 %14, label %15, label %19
15: ; preds = %7
%16 = getelementptr inbounds i8*, i8** %1, i64 3
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
br label %19
19: ; preds = %7, %15
%20 = phi i32 [ %18, %15 ], [ 1, %7 ]
%21 = icmp ugt i32 %0, 4
%22 = icmp eq i32 %0, 6
%23 = tail call i32 @srand(i32 %10)
%24 = tail call i32 @getNumClauses(i32 %13)
%25 = mul i32 %24, 12
%26 = tail call i32* @malloc(i32 %25)
%27 = shl i32 %13, 2
%28 = tail call i32* @malloc(i32 %27)
%29 = tail call i32 @getRandomEquAndSol(i32* %26, i32* %28, i32 %13, i32 %24)
br i1 %21, label %30, label %34
30: ; preds = %19
%31 = getelementptr inbounds i8*, i8** %1, i64 4
%32 = load i8*, i8** %31
%33 = tail call i32 @saveEquation(i8* %32, i32* %26, i32 %24)
br label %34
34: ; preds = %30, %19
%35 = icmp eq i32 %20, 0
br i1 %35, label %38, label %36
36: ; preds = %34
%37 = tail call i32 @printEquation(i32* %26, i32 %24)
br label %38
38: ; preds = %36, %34
br i1 %22, label %39, label %43
39: ; preds = %38
%40 = getelementptr inbounds i8*, i8** %1, i64 5
%41 = load i8*, i8** %40
%42 = tail call i32 @saveSolution(i8* %41, i32* %28, i32 %13)
br label %43
43: ; preds = %39, %38
%44 = tail call i32 @free(i32* %26)
%45 = tail call i32 @free(i32* %28)
br label %46
46: ; preds = %43, %5
%47 = phi i32 [ 1, %5 ], [ 0, %43 ]
ret i32 %47
}