#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 BitMatrix {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ BitMatrixSet(struct BitMatrix *, unsigned int, unsigned int,
                                int);
struct BitMatrix *newBitMatrixZero(unsigned int, unsigned int);
struct BitMatrix *newBitMatrixIdentity(unsigned int rows) {
  struct BitMatrix *mat = newBitMatrixZero(rows, rows);
  for (unsigned int i = 0; i < rows; i++) {
    BitMatrixSet(mat, i, i, 1);
  }
  return mat;
}


x86 assembly (clang, -O0):
<newBitMatrixIdentity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1040 <newBitMatrixZero@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    116f <newBitMatrixIdentity+0x4f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    $0x1,%ecx
call   1030 <BitMatrixSet@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1141 <newBitMatrixIdentity+0x21>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newBitMatrixIdentity>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    %edi,%esi
call   1040 <newBitMatrixZero@plt>
mov    %rax,%rbx
test   %r14d,%r14d
je     1159 <newBitMatrixIdentity+0x39>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
mov    $0x1,%ecx
call   1030 <BitMatrixSet@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1140 <newBitMatrixIdentity+0x20>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.BitMatrix = type { i32 }
define %struct.BitMatrix* @newBitMatrixIdentity(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.BitMatrix*
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* %2
%7 = call %struct.BitMatrix* @newBitMatrixZero(i32 %5, i32 %6)
store %struct.BitMatrix* %7, %struct.BitMatrix** %3
store i32 0, i32* %4
br label %8
8: ; preds = %17, %1
%9 = load i32, i32* %4
%10 = load i32, i32* %2
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = load %struct.BitMatrix*, %struct.BitMatrix** %3
%14 = load i32, i32* %4
%15 = load i32, i32* %4
%16 = call i32 @BitMatrixSet(%struct.BitMatrix* %13, i32 %14, i32 %15, i32 1)
br label %17
17: ; preds = %12
%18 = load i32, i32* %4
%19 = add i32 %18, 1
store i32 %19, i32* %4
br label %8
20: ; preds = %8
%21 = load %struct.BitMatrix*, %struct.BitMatrix** %3
ret %struct.BitMatrix* %21
}

LLVM IR (-O2):
%struct.BitMatrix = type { i32 }
define %struct.BitMatrix* @newBitMatrixIdentity(i32 %0) {
%2 = tail call %struct.BitMatrix* @newBitMatrixZero(i32 %0, i32 %0)
%3 = icmp eq i32 %0, 0
br i1 %3, label %4, label %5
4: ; preds = %5, %1
ret %struct.BitMatrix* %2
5: ; preds = %1, %5
%6 = phi i32 [ %8, %5 ], [ 0, %1 ]
%7 = tail call i32 @BitMatrixSet(%struct.BitMatrix* %2, i32 %6, i32 %6, i32 1)
%8 = add nuw i32 %6, 1
%9 = icmp eq i32 %8, %0
br i1 %9, label %4, label %5
}