#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 hd_geometry {
  unsigned int heads;
  unsigned int sectors;
};

/* Variables and functions */
bool chs2lba(int fd, const struct hd_geometry *geometry, unsigned int c,
             unsigned int h, unsigned int s, unsigned int *sector) {
  bool success = false;
  if ((h == 0xff) || (s == 0)) {
    success = false;
  } else {
    *sector = (c * geometry->heads + h) * geometry->sectors + (s - 1);
    success = true;
  }
  return (success);
}


x86 assembly (clang, -O0):
<chs2lba>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0xff,-0x18(%rbp)
je     1137 <chs2lba+0x37>
cmpl   $0x0,-0x1c(%rbp)
jne    1143 <chs2lba+0x43>
movl   $0x0,-0x2c(%rbp)
jmp    116d <chs2lba+0x6d>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
imul   (%rax),%ecx
add    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
imul   0x4(%rax),%ecx
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
add    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<chs2lba>:
xor    %eax,%eax
cmp    $0xff,%ecx
je     1127 <chs2lba+0x27>
test   %r8d,%r8d
je     1127 <chs2lba+0x27>
imul   (%rsi),%edx
add    %ecx,%edx
imul   0x4(%rsi),%edx
lea    (%r8,%rdx,1),%eax
add    $0xffffffff,%eax
mov    %eax,(%r9)
mov    $0x1,%eax
ret

LLVM IR (-O0):
%struct.hd_geometry = type { i32, i32 }
define i32 @chs2lba(i32 %0, %struct.hd_geometry* %1, i32 %2, i32 %3, i32 %4, i32* %5) {
%7 = alloca i32
%8 = alloca %struct.hd_geometry*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
store i32 %0, i32* %7
store %struct.hd_geometry* %1, %struct.hd_geometry** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32* %5, i32** %12
store i32 0, i32* %13
%14 = load i32, i32* %10
%15 = icmp eq i32 %14, 255
br i1 %15, label %19, label %16
16: ; preds = %6
%17 = load i32, i32* %11
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16, %6
store i32 0, i32* %13
br label %36
20: ; preds = %16
%21 = load i32, i32* %9
%22 = load %struct.hd_geometry*, %struct.hd_geometry** %8
%23 = getelementptr inbounds %struct.hd_geometry, %struct.hd_geometry* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = mul i32 %21, %24
%26 = load i32, i32* %10
%27 = add i32 %25, %26
%28 = load %struct.hd_geometry*, %struct.hd_geometry** %8
%29 = getelementptr inbounds %struct.hd_geometry, %struct.hd_geometry* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = mul i32 %27, %30
%32 = load i32, i32* %11
%33 = sub i32 %32, 1
%34 = add i32 %31, %33
%35 = load i32*, i32** %12
store i32 %34, i32* %35
store i32 1, i32* %13
br label %36
36: ; preds = %20, %19
%37 = load i32, i32* %13
ret i32 %37
}

LLVM IR (-O2):
%struct.hd_geometry = type { i32, i32 }
define i32 @chs2lba(i32 %0, %struct.hd_geometry* nocapture %1, i32 %2, i32 %3, i32 %4, i32* nocapture writeonly %5) {
%7 = icmp eq i32 %3, 255
%8 = icmp eq i32 %4, 0
%9 = or i1 %7, %8
br i1 %9, label %20, label %10
10: ; preds = %6
%11 = getelementptr inbounds %struct.hd_geometry, %struct.hd_geometry* %1, i64 0, i32 0
%12 = load i32, i32* %11
%13 = mul i32 %12, %2
%14 = add i32 %13, %3
%15 = getelementptr inbounds %struct.hd_geometry, %struct.hd_geometry* %1, i64 0, i32 1
%16 = load i32, i32* %15
%17 = mul i32 %14, %16
%18 = add i32 %4, -1
%19 = add i32 %18, %17
store i32 %19, i32* %5
br label %20
20: ; preds = %6, %10
%21 = phi i32 [ 1, %10 ], [ 0, %6 ]
ret i32 %21
}