#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*/ readSector(char *, int);
int /*<<< orphan*/ writeSector(char *, int);
int findFreeSector() {
  char sut[512];
  int i;
  int byte, bit;
  readSector(sut, 1);
  for (i = 0; i < 4096; i++) {
    byte = i >> 3;
    bit = 7 - (i & 0x7);
    if (!(sut[byte] & (1 << bit))) {
      sut[byte] |= 1 << bit;
      writeSector(sut, 1);
      return i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<findFreeSector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
lea    -0x210(%rbp),%rdi
mov    $0x1,%esi
call   1040 <readSector@plt>
movl   $0x0,-0x214(%rbp)
cmpl   $0x1000,-0x214(%rbp)
jge    1201 <findFreeSector+0xe1>
mov    -0x214(%rbp),%eax
sar    $0x3,%eax
mov    %eax,-0x218(%rbp)
mov    -0x214(%rbp),%ecx
and    $0x7,%ecx
mov    $0x7,%eax
sub    %ecx,%eax
mov    %eax,-0x21c(%rbp)
movslq -0x218(%rbp),%rax
movsbl -0x210(%rbp,%rax,1),%eax
ff
mov    -0x21c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    11e8 <findFreeSector+0xc8>
mov    -0x21c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
movslq -0x218(%rbp),%rax
movsbl -0x210(%rbp,%rax,1),%ecx
ff
or     %edx,%ecx
mov    %cl,-0x210(%rbp,%rax,1)
lea    -0x210(%rbp),%rdi
mov    $0x1,%esi
call   1030 <writeSector@plt>
mov    -0x214(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1208 <findFreeSector+0xe8>
jmp    11ed <findFreeSector+0xcd>
mov    -0x214(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x214(%rbp)
jmp    1146 <findFreeSector+0x26>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findFreeSector>:
push   %rbx
sub    $0x200,%rsp
mov    %rsp,%rdi
mov    $0x1,%esi
call   1040 <readSector@plt>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebx,%eax
mov    %rax,%rdi
mov    %ebx,%ecx
and    $0x6,%cl
xor    $0x7,%cl
mov    $0x1,%edx
shl    %cl,%edx
shr    $0x3,%rdi
movzbl (%rsp,%rdi,1),%esi
movzbl %cl,%ecx
bt     %ecx,%esi
jae    1199 <findFreeSector+0x79>
mov    %ebx,%ecx
not    %cl
and    $0x6,%cl
mov    $0x1,%edx
shl    %cl,%edx
shr    $0x3,%rax
movzbl (%rsp,%rax,1),%esi
movzbl %cl,%ecx
bt     %ecx,%esi
jae    1194 <findFreeSector+0x74>
add    $0x2,%ebx
cmp    $0x1000,%ebx
jne    1140 <findFreeSector+0x20>
mov    $0xffffffff,%ebx
jmp    11ae <findFreeSector+0x8e>
add    $0x1,%ebx
mov    %eax,%edi
mov    %edi,%eax
or     %sil,%dl
mov    %dl,(%rsp,%rax,1)
mov    %rsp,%rdi
mov    $0x1,%esi
call   1030 <writeSector@plt>
mov    %ebx,%eax
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @findFreeSector() {
%1 = alloca i32
%2 = alloca [512 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%7 = call i32 @readSector(i8* %6, i32 1)
store i32 0, i32* %3
br label %8
8: ; preds = %40, %0
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 4096
br i1 %10, label %11, label %43
11: ; preds = %8
%12 = load i32, i32* %3
%13 = ashr i32 %12, 3
store i32 %13, i32* %4
%14 = load i32, i32* %3
%15 = and i32 %14, 7
%16 = sub nsw i32 7, %15
store i32 %16, i32* %5
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = load i32, i32* %5
%23 = shl i32 1, %22
%24 = and i32 %21, %23
%25 = icmp ne i32 %24, 0
br i1 %25, label %39, label %26
26: ; preds = %11
%27 = load i32, i32* %5
%28 = shl i32 1, %27
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = or i32 %33, %28
%35 = trunc i32 %34 to i8
store i8 %35, i8* %31
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%37 = call i32 @writeSector(i8* %36, i32 1)
%38 = load i32, i32* %3
store i32 %38, i32* %1
br label %44
39: ; preds = %11
br label %40
40: ; preds = %39
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
store i32 %42, i32* %3
br label %8
43: ; preds = %8
store i32 -1, i32* %1
br label %44
44: ; preds = %43, %26
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
define i32 @findFreeSector() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = call i32 @readSector(i8* %2, i32 1)
br label %4
4: ; preds = %39, %0
%5 = phi i32 [ 0, %0 ], [ %40, %39 ]
%6 = lshr i32 %5, 3
%7 = and i32 %5, 6
%8 = xor i32 %7, 7
%9 = zext i32 %6 to i64
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = shl nuw i32 1, %8
%14 = and i32 %13, %12
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %28
16: ; preds = %28
%17 = or i32 %5, 1
br label %18
18: ; preds = %4, %16
%19 = phi i32 [ %17, %16 ], [ %5, %4 ]
%20 = phi i32 [ %29, %16 ], [ %6, %4 ]
%21 = phi i8 [ %34, %16 ], [ %11, %4 ]
%22 = phi i32 [ %36, %16 ], [ %13, %4 ]
%23 = zext i32 %20 to i64
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 %23
%25 = trunc i32 %22 to i8
%26 = or i8 %21, %25
store i8 %26, i8* %24
%27 = call i32 @writeSector(i8* %2, i32 1)
br label %42
28: ; preds = %4
%29 = lshr i32 %5, 3
%30 = and i32 %5, 6
%31 = xor i32 %30, 6
%32 = zext i32 %29 to i64
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = shl nuw i32 1, %31
%37 = and i32 %36, %35
%38 = icmp eq i32 %37, 0
br i1 %38, label %16, label %39
39: ; preds = %28
%40 = add nuw nsw i32 %5, 2
%41 = icmp eq i32 %40, 4096
br i1 %41, label %42, label %4
42: ; preds = %39, %18
%43 = phi i32 [ %19, %18 ], [ -1, %39 ]
ret i32 %43
}