#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int lba, c, h, s;
  if (argc != 2) {
    printf("Usage: off2chs <offset>\n");
    exit(1);
  }
  lba = atoi(argv[1]);
  c = lba / (18 * 2);
  h = (lba / 18) % 2;
  s = lba % 18 + 1;
  printf("c,h,s = %d,%d,%d\n", c, h, s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1168 <main+0x38>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x24,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x12,%ecx
cltd
idiv   %ecx
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x12,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x2,%edi
jne    119a <main+0x5a>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
cltq
imul   $0x38e38e39,%rax,%rcx
mov    %rcx,%rsi
sar    $0x23,%rsi
mov    %rcx,%rdx
shr    $0x3f,%rdx
add    %edx,%esi
sar    $0x22,%rcx
add    %edx,%ecx
mov    %ecx,%edi
shr    $0x1f,%edi
add    %ecx,%edi
and    $0xfffffffe,%edi
mov    %ecx,%edx
sub    %edi,%edx
add    %ecx,%ecx
lea    (%rcx,%rcx,8),%ecx
neg    %ecx
add    %eax,%ecx
add    $0x1,%ecx
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Usage: off2chs <offset>\0A\00"
@.str.1 = [18 x i8] c"c,h,s = %d,%d,%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = sdiv i32 %20, 36
store i32 %21, i32* %7
%22 = load i32, i32* %6
%23 = sdiv i32 %22, 18
%24 = srem i32 %23, 2
store i32 %24, i32* %8
%25 = load i32, i32* %6
%26 = srem i32 %25, 18
%27 = add nsw i32 %26, 1
store i32 %27, i32* %9
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = load i32, i32* %9
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %28, i32 %29, i32 %30)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [18 x i8] c"c,h,s = %d,%d,%d\0A\00"
@str = [24 x i8] c"Usage: off2chs <offset>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = sdiv i32 %10, 36
%12 = sdiv i32 %10, 18
%13 = srem i32 %12, 2
%14 = srem i32 %10, 18
%15 = add nsw i32 %14, 1
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %13, i32 %15)
ret i32 0
}