#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 */
struct connect4 {
  int dummy;
};

/* Variables and functions */
int get_row(struct connect4 const *, int);
int *malloc(int);
int *get_possible_moves(const struct connect4 *game) {
  int *list = malloc(sizeof(int) * 7);
  int i;
  for (i = 0; i < 7; i++)
    list[i] = (get_row(game, i) < 6);
  return list;
}


x86 assembly (clang, -O0):
<get_possible_moves>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x1c,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x7,-0x14(%rbp)
jge    117b <get_possible_moves+0x5b>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <get_row@plt>
cmp    $0x6,%eax
setl   %al
and    $0x1,%al
movzbl %al,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1141 <get_possible_moves+0x21>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_possible_moves>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    $0x1c,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <get_row@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <get_row@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <get_row@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x3,%esi
call   1030 <get_row@plt>
movd   %r15d,%xmm0
movd   %r12d,%xmm1
punpckldq %xmm1,%xmm0
movd   %ebp,%xmm1
movd   %eax,%xmm2
punpckldq %xmm2,%xmm1
punpcklqdq %xmm1,%xmm0
movdqa 0xe69(%rip),%xmm1
pcmpgtd %xmm0,%xmm1
psrld  $0x1f,%xmm1
movdqu %xmm1,(%r14)
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <get_row@plt>
xor    %ecx,%ecx
cmp    $0x6,%eax
setl   %cl
mov    %ecx,0x10(%r14)
mov    %rbx,%rdi
mov    $0x5,%esi
call   1030 <get_row@plt>
xor    %ecx,%ecx
cmp    $0x6,%eax
setl   %cl
mov    %ecx,0x14(%r14)
mov    %rbx,%rdi
mov    $0x6,%esi
call   1030 <get_row@plt>
xor    %ecx,%ecx
cmp    $0x6,%eax
setl   %cl
mov    %ecx,0x18(%r14)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.connect4 = type { i32 }
define i32* @get_possible_moves(%struct.connect4* %0) {
%2 = alloca %struct.connect4*
%3 = alloca i32*
%4 = alloca i32
store %struct.connect4* %0, %struct.connect4** %2
%5 = call i32* @malloc(i32 28)
store i32* %5, i32** %3
store i32 0, i32* %4
br label %6
6: ; preds = %19, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 7
br i1 %8, label %9, label %22
9: ; preds = %6
%10 = load %struct.connect4*, %struct.connect4** %2
%11 = load i32, i32* %4
%12 = call i32 @get_row(%struct.connect4* %10, i32 %11)
%13 = icmp slt i32 %12, 6
%14 = zext i1 %13 to i32
%15 = load i32*, i32** %3
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
store i32 %14, i32* %18
br label %19
19: ; preds = %9
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %6
22: ; preds = %6
%23 = load i32*, i32** %3
ret i32* %23
}

LLVM IR (-O2):
%struct.connect4 = type { i32 }
define noalias i32* @get_possible_moves(%struct.connect4* %0) {
%2 = tail call i32* @malloc(i32 28)
%3 = tail call i32 @get_row(%struct.connect4* %0, i32 0)
%4 = tail call i32 @get_row(%struct.connect4* %0, i32 1)
%5 = tail call i32 @get_row(%struct.connect4* %0, i32 2)
%6 = tail call i32 @get_row(%struct.connect4* %0, i32 3)
%7 = insertelement <4 x i32> poison, i32 %3, i64 0
%8 = insertelement <4 x i32> %7, i32 %4, i64 1
%9 = insertelement <4 x i32> %8, i32 %5, i64 2
%10 = insertelement <4 x i32> %9, i32 %6, i64 3
%11 = icmp slt <4 x i32> %10, <i32 6, i32 6, i32 6, i32 6>
%12 = zext <4 x i1> %11 to <4 x i32>
%13 = bitcast i32* %2 to <4 x i32>*
store <4 x i32> %12, <4 x i32>* %13
%14 = tail call i32 @get_row(%struct.connect4* %0, i32 4)
%15 = icmp slt i32 %14, 6
%16 = zext i1 %15 to i32
%17 = getelementptr inbounds i32, i32* %2, i64 4
store i32 %16, i32* %17
%18 = tail call i32 @get_row(%struct.connect4* %0, i32 5)
%19 = icmp slt i32 %18, 6
%20 = zext i1 %19 to i32
%21 = getelementptr inbounds i32, i32* %2, i64 5
store i32 %20, i32* %21
%22 = tail call i32 @get_row(%struct.connect4* %0, i32 6)
%23 = icmp slt i32 %22, 6
%24 = zext i1 %23 to i32
%25 = getelementptr inbounds i32, i32* %2, i64 6
store i32 %24, i32* %25
ret i32* %2
}