#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*/ printf(char *, ...);
scalar_t__ wPrefersM1OverM(int **, int, int, int, int);
void stableMarriage(int prefer[2 * 1000][1000], int a) {
  int size = a;
  int wPartner[1000];
  for (int i = 0; i < 1000; i++)
    wPartner[i] = -1;
  int mFree[1000] = {0};
  int freeCount = a;
  while (freeCount > 0) {
    int m;
    for (m = 0; m < a; m++)
      if (mFree[m] == 0)
        break;
    for (int i = 0; i < a && mFree[m] == 0; i++) {
      int w = prefer[m][i];
      if (wPartner[w - a] == -1) {
        wPartner[w - a] = m;
        mFree[m] = 1;
        freeCount--;
      } else {
        int m1 = wPartner[w - a];
        if (wPrefersM1OverM(prefer, w, m, m1, a) == 0) {
          wPartner[w - a] = m;
          mFree[m] = 1;
          mFree[m1] = 0;
        }
      }
    }
  }
  printf("W   M\n");
  for (int i = 0; i < a; i++)
    printf(" %d    %d\n", i + a, wPartner[i]);
}


x86 assembly (clang, -O0):
<stableMarriage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xfb4(%rbp)
cmpl   $0x3e8,-0xfb4(%rbp)
jge    1188 <stableMarriage+0x58>
movslq -0xfb4(%rbp),%rax
movl   $0xffffffff,-0xfb0(%rbp,%rax,4)
ff ff ff ff
mov    -0xfb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb4(%rbp)
jmp    1152 <stableMarriage+0x22>
lea    -0x1f60(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa0,%edx
call   1040 <memset@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1f64(%rbp)
cmpl   $0x0,-0x1f64(%rbp)
jle    1365 <stableMarriage+0x235>
movl   $0x0,-0x1f68(%rbp)
mov    -0x1f68(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11fd <stableMarriage+0xcd>
movslq -0x1f68(%rbp),%rax
cmpl   $0x0,-0x1f60(%rbp,%rax,4)
jne    11e4 <stableMarriage+0xb4>
jmp    11fd <stableMarriage+0xcd>
jmp    11e9 <stableMarriage+0xb9>
mov    -0x1f68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f68(%rbp)
jmp    11bb <stableMarriage+0x8b>
movl   $0x0,-0x1f6c(%rbp)
mov    -0x1f6c(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x1f79(%rbp)
jge    1236 <stableMarriage+0x106>
movslq -0x1f68(%rbp),%rax
cmpl   $0x0,-0x1f60(%rbp,%rax,4)
sete   %al
mov    %al,-0x1f79(%rbp)
mov    -0x1f79(%rbp),%al
test   $0x1,%al
jne    1249 <stableMarriage+0x119>
jmp    1360 <stableMarriage+0x230>
mov    -0x8(%rbp),%rax
movslq -0x1f68(%rbp),%rcx
imul   $0xfa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x1f6c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1f70(%rbp)
mov    -0x1f70(%rbp),%eax
sub    -0xc(%rbp),%eax
cltq
cmpl   $0xffffffff,-0xfb0(%rbp,%rax,4)
ff
jne    12c5 <stableMarriage+0x195>
mov    -0x1f68(%rbp),%ecx
mov    -0x1f70(%rbp),%eax
sub    -0xc(%rbp),%eax
cltq
mov    %ecx,-0xfb0(%rbp,%rax,4)
movslq -0x1f68(%rbp),%rax
movl   $0x1,-0x1f60(%rbp,%rax,4)
mov    -0x1f64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1f64(%rbp)
jmp    1347 <stableMarriage+0x217>
mov    -0x1f70(%rbp),%eax
sub    -0xc(%rbp),%eax
cltq
mov    -0xfb0(%rbp,%rax,4),%eax
mov    %eax,-0x1f74(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1f70(%rbp),%esi
mov    -0x1f68(%rbp),%edx
mov    -0x1f74(%rbp),%ecx
mov    -0xc(%rbp),%r8d
call   1050 <wPrefersM1OverM@plt>
cmp    $0x0,%rax
jne    1342 <stableMarriage+0x212>
mov    -0x1f68(%rbp),%ecx
mov    -0x1f70(%rbp),%eax
sub    -0xc(%rbp),%eax
cltq
mov    %ecx,-0xfb0(%rbp,%rax,4)
movslq -0x1f68(%rbp),%rax
movl   $0x1,-0x1f60(%rbp,%rax,4)
movslq -0x1f74(%rbp),%rax
movl   $0x0,-0x1f60(%rbp,%rax,4)
jmp    1347 <stableMarriage+0x217>
jmp    134c <stableMarriage+0x21c>
mov    -0x1f6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f6c(%rbp)
jmp    1207 <stableMarriage+0xd7>
jmp    11a4 <stableMarriage+0x74>
lea    0xc94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1f78(%rbp)
mov    -0x1f78(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    13c5 <stableMarriage+0x295>
mov    -0x1f78(%rbp),%esi
add    -0xc(%rbp),%esi
movslq -0x1f78(%rbp),%rax
mov    -0xfb0(%rbp,%rax,4),%edx
lea    0xc5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1f78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f78(%rbp)
jmp    137d <stableMarriage+0x24d>
add    $0x1f80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stableMarriage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f68,%rsp
mov    %esi,%ebx
mov    %rdi,0x10(%rsp)
lea    0xfc0(%rsp),%rdi
mov    $0xfa0,%edx
mov    $0xff,%esi
call   1050 <memset@plt>
lea    0x20(%rsp),%rdi
mov    $0xfa0,%edx
xor    %esi,%esi
call   1050 <memset@plt>
test   %ebx,%ebx
jle    12c4 <stableMarriage+0x184>
mov    %ebx,%r8d
mov    %ebx,%ecx
mov    %ebx,0x4(%rsp)
mov    %rcx,0x8(%rsp)
jmp    11ab <stableMarriage+0x6b>
nopl   0x0(%rax,%rax,1)
cmpl   $0x0,0x4(%rsp)
jle    1268 <stableMarriage+0x128>
xor    %ebx,%ebx
nopl   (%rax)
cmpl   $0x0,0x20(%rsp,%rbx,4)
je     11c2 <stableMarriage+0x82>
add    $0x1,%rbx
cmp    %rbx,%rcx
jne    11b0 <stableMarriage+0x70>
mov    %ecx,%ebx
mov    %ebx,%r14d
imul   $0xfa0,%r14,%rax
add    0x10(%rsp),%rax
mov    %rax,0x18(%rsp)
xor    %r15d,%r15d
jmp    11f1 <stableMarriage+0xb1>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rcx
mov    %r13d,%r8d
add    $0x1,%r15
cmp    %r15,%rcx
je     11a0 <stableMarriage+0x60>
cmpl   $0x0,0x20(%rsp,%r14,4)
jne    11a0 <stableMarriage+0x60>
mov    0x18(%rsp),%rax
mov    (%rax,%r15,4),%esi
mov    %esi,%eax
sub    %r8d,%eax
movslq %eax,%r12
movslq 0xfc0(%rsp,%r12,4),%rbp
cmp    $0xffffffffffffffff,%rbp
je     1250 <stableMarriage+0x110>
mov    0x10(%rsp),%rdi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r8d,%r13d
call   1060 <wPrefersM1OverM@plt>
test   %rax,%rax
jne    11e0 <stableMarriage+0xa0>
mov    %ebx,0xfc0(%rsp,%r12,4)
movl   $0x1,0x20(%rsp,%r14,4)
movl   $0x0,0x20(%rsp,%rbp,4)
jmp    11e0 <stableMarriage+0xa0>
nopl   0x0(%rax)
mov    %ebx,0xfc0(%rsp,%r12,4)
movl   $0x1,0x20(%rsp,%r14,4)
addl   $0xffffffff,0x4(%rsp)
jmp    11e8 <stableMarriage+0xa8>
lea    0xd9c(%rip),%rdi
mov    %r8d,%ebx
call   1030 <puts@plt>
mov    0x8(%rsp),%rax
test   %ebx,%ebx
jle    12b2 <stableMarriage+0x172>
lea    0xd79(%rip),%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    0xfc0(%rsp,%rbp,4),%edx
lea    (%rax,%rbp,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rax
add    $0x1,%rbp
cmp    %rbp,%rax
jne    1290 <stableMarriage+0x150>
add    $0x1f68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd40(%rip),%rdi
add    $0x1f68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"W M\0A\00"
@.str.1 = [11 x i8] c" %d %d\0A\00"
define void @stableMarriage([1000 x i32]* %0, i32 %1) {
%3 = alloca [1000 x i32]*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1000 x i32]
%7 = alloca i32
%8 = alloca [1000 x i32]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store [1000 x i32]* %0, [1000 x i32]** %3
store i32 %1, i32* %4
%15 = load i32, i32* %4
store i32 %15, i32* %5
store i32 0, i32* %7
br label %16
16: ; preds = %23, %2
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 1000
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %21
store i32 -1, i32* %22
br label %23
23: ; preds = %19
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %16
26: ; preds = %16
%27 = bitcast [1000 x i32]* %8 to i8*
%28 = load i32, i32* %4
store i32 %28, i32* %9
br label %29
29: ; preds = %122, %26
%30 = load i32, i32* %9
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %123
32: ; preds = %29
store i32 0, i32* %10
br label %33
33: ; preds = %45, %32
%34 = load i32, i32* %10
%35 = load i32, i32* %4
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %48
37: ; preds = %33
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [1000 x i32], [1000 x i32]* %8, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %37
br label %48
44: ; preds = %37
br label %45
45: ; preds = %44
%46 = load i32, i32* %10
%47 = add nsw i32 %46, 1
store i32 %47, i32* %10
br label %33
48: ; preds = %43, %33
store i32 0, i32* %11
br label %49
49: ; preds = %119, %48
%50 = load i32, i32* %11
%51 = load i32, i32* %4
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %59
53: ; preds = %49
%54 = load i32, i32* %10
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [1000 x i32], [1000 x i32]* %8, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = icmp eq i32 %57, 0
br label %59
59: ; preds = %53, %49
%60 = phi i1 [ false, %49 ], [ %58, %53 ]
br i1 %60, label %61, label %122
61: ; preds = %59
%62 = load [1000 x i32]*, [1000 x i32]** %3
%63 = load i32, i32* %10
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [1000 x i32], [1000 x i32]* %62, i64 %64
%66 = load i32, i32* %11
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [1000 x i32], [1000 x i32]* %65, i64 0, i64 %67
%69 = load i32, i32* %68
store i32 %69, i32* %12
%70 = load i32, i32* %12
%71 = load i32, i32* %4
%72 = sub nsw i32 %70, %71
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %73
%75 = load i32, i32* %74
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %89
77: ; preds = %61
%78 = load i32, i32* %10
%79 = load i32, i32* %12
%80 = load i32, i32* %4
%81 = sub nsw i32 %79, %80
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %82
store i32 %78, i32* %83
%84 = load i32, i32* %10
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [1000 x i32], [1000 x i32]* %8, i64 0, i64 %85
store i32 1, i32* %86
%87 = load i32, i32* %9
%88 = add nsw i32 %87, -1
store i32 %88, i32* %9
br label %118
89: ; preds = %61
%90 = load i32, i32* %12
%91 = load i32, i32* %4
%92 = sub nsw i32 %90, %91
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %93
%95 = load i32, i32* %94
store i32 %95, i32* %13
%96 = load [1000 x i32]*, [1000 x i32]** %3
%97 = bitcast [1000 x i32]* %96 to i32**
%98 = load i32, i32* %12
%99 = load i32, i32* %10
%100 = load i32, i32* %13
%101 = load i32, i32* %4
%102 = call i64 @wPrefersM1OverM(i32** %97, i32 %98, i32 %99, i32 %100, i32 %101)
%103 = icmp eq i64 %102, 0
br i1 %103, label %104, label %117
104: ; preds = %89
%105 = load i32, i32* %10
%106 = load i32, i32* %12
%107 = load i32, i32* %4
%108 = sub nsw i32 %106, %107
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %109
store i32 %105, i32* %110
%111 = load i32, i32* %10
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds [1000 x i32], [1000 x i32]* %8, i64 0, i64 %112
store i32 1, i32* %113
%114 = load i32, i32* %13
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds [1000 x i32], [1000 x i32]* %8, i64 0, i64 %115
store i32 0, i32* %116
br label %117
117: ; preds = %104, %89
br label %118
118: ; preds = %117, %77
br label %119
119: ; preds = %118
%120 = load i32, i32* %11
%121 = add nsw i32 %120, 1
store i32 %121, i32* %11
br label %49
122: ; preds = %59
br label %29
123: ; preds = %29
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %14
br label %125
125: ; preds = %138, %123
%126 = load i32, i32* %14
%127 = load i32, i32* %4
%128 = icmp slt i32 %126, %127
br i1 %128, label %129, label %141
129: ; preds = %125
%130 = load i32, i32* %14
%131 = load i32, i32* %4
%132 = add nsw i32 %130, %131
%133 = load i32, i32* %14
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %134
%136 = load i32, i32* %135
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %132, i32 %136)
br label %138
138: ; preds = %129
%139 = load i32, i32* %14
%140 = add nsw i32 %139, 1
store i32 %140, i32* %14
br label %125
141: ; preds = %125
ret void
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c" %d %d\0A\00"
@str = [6 x i8] c"W M\00"
define void @stableMarriage([1000 x i32]* %0, i32 %1) {
%3 = alloca [1000 x i32]
%4 = bitcast [1000 x i32]* %3 to i8*
%5 = alloca [1000 x i32]
%6 = bitcast [1000 x i32]* %5 to i8*
%7 = icmp sgt i32 %1, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %62
10: ; preds = %2
%11 = bitcast [1000 x i32]* %0 to i32**
%12 = zext i32 %1 to i64
%13 = zext i32 %1 to i64
br label %14
14: ; preds = %35, %10
%15 = phi i32 [ %1, %10 ], [ %36, %35 ]
br label %16
16: ; preds = %14, %21
%17 = phi i64 [ 0, %14 ], [ %22, %21 ]
%18 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = add nuw nsw i64 %17, 1
%23 = icmp eq i64 %22, %12
br i1 %23, label %26, label %16
24: ; preds = %16
%25 = trunc i64 %17 to i32
br label %26
26: ; preds = %21, %24
%27 = phi i32 [ %25, %24 ], [ %1, %21 ]
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 %28
br label %30
30: ; preds = %26, %54
%31 = phi i64 [ 0, %26 ], [ %56, %54 ]
%32 = phi i32 [ %15, %26 ], [ %55, %54 ]
%33 = load i32, i32* %29
%34 = icmp eq i32 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %30, %54
%36 = phi i32 [ %32, %30 ], [ %55, %54 ]
%37 = icmp sgt i32 %36, 0
br i1 %37, label %14, label %58
38: ; preds = %30
%39 = getelementptr inbounds [1000 x i32], [1000 x i32]* %0, i64 %28, i64 %31
%40 = load i32, i32* %39
%41 = sub nsw i32 %40, %1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %38
store i32 %27, i32* %43
store i32 1, i32* %29
%47 = add nsw i32 %32, -1
br label %54
48: ; preds = %38
%49 = tail call i64 @wPrefersM1OverM(i32** %11, i32 %40, i32 %27, i32 %44, i32 %1)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48
store i32 %27, i32* %43
store i32 1, i32* %29
%52 = sext i32 %44 to i64
%53 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 %52
store i32 0, i32* %53
br label %54
54: ; preds = %48, %51, %46
%55 = phi i32 [ %47, %46 ], [ %32, %51 ], [ %32, %48 ]
%56 = add nuw nsw i64 %31, 1
%57 = icmp eq i64 %56, %13
br i1 %57, label %35, label %30
58: ; preds = %35
%59 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br i1 %7, label %60, label %62
60: ; preds = %58
%61 = zext i32 %1 to i64
br label %63
62: ; preds = %63, %8, %58
ret void
63: ; preds = %60, %63
%64 = phi i64 [ 0, %60 ], [ %70, %63 ]
%65 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 %64
%66 = load i32, i32* %65
%67 = trunc i64 %64 to i32
%68 = add i32 %67, %1
%69 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %68, i32 %66)
%70 = add nuw nsw i64 %64, 1
%71 = icmp eq i64 %70, %61
br i1 %71, label %62, label %63
}