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

/* Variables and functions */
int /*<<< orphan*/ HDIO_GETGEO;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct hd_geometry *);
int /*<<< orphan*/ printf(char *, int, int);
bool get_disk_geometry(int fd, struct hd_geometry *geometry) {
  bool success = true;
  if (ioctl(fd, HDIO_GETGEO, geometry)) {
    geometry->heads = 255;
    geometry->sectors = 63;
  }
  printf("Using disk geometry of %u heads and %u sectors/track for CHS "
         "translation\n",
         geometry->heads, geometry->sectors);
  return (success);
}


x86 assembly (clang, -O0):
<get_disk_geometry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     116a <get_disk_geometry+0x4a>
mov    -0x10(%rbp),%rax
movl   $0xff,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3f,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_disk_geometry>:
push   %rbx
mov    %rsi,%rbx
mov    0x2ebd(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
je     1153 <get_disk_geometry+0x33>
movabs $0x3f000000ff,%rax
mov    %rax,(%rbx)
mov    $0xff,%esi
mov    $0x3f,%edx
jmp    1158 <get_disk_geometry+0x38>
mov    (%rbx),%esi
mov    0x4(%rbx),%edx
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.hd_geometry = type { i32, i32 }
@HDIO_GETGEO = global i32 0
@.str = [74 x i8] c"Using disk geometry of %u heads and %u sectors/track for CHS translation\0A\00"
define i32 @get_disk_geometry(i32 %0, %struct.hd_geometry* %1) {
%3 = alloca i32
%4 = alloca %struct.hd_geometry*
%5 = alloca i32
store i32 %0, i32* %3
store %struct.hd_geometry* %1, %struct.hd_geometry** %4
store i32 1, i32* %5
%6 = load i32, i32* %3
%7 = load i32, i32* @HDIO_GETGEO
%8 = load %struct.hd_geometry*, %struct.hd_geometry** %4
%9 = call i64 @ioctl(i32 %6, i32 %7, %struct.hd_geometry* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load %struct.hd_geometry*, %struct.hd_geometry** %4
%13 = getelementptr inbounds %struct.hd_geometry, %struct.hd_geometry* %12, i32 0, i32 0
store i32 255, i32* %13
%14 = load %struct.hd_geometry*, %struct.hd_geometry** %4
%15 = getelementptr inbounds %struct.hd_geometry, %struct.hd_geometry* %14, i32 0, i32 1
store i32 63, i32* %15
br label %16
16: ; preds = %11, %2
%17 = load %struct.hd_geometry*, %struct.hd_geometry** %4
%18 = getelementptr inbounds %struct.hd_geometry, %struct.hd_geometry* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = load %struct.hd_geometry*, %struct.hd_geometry** %4
%21 = getelementptr inbounds %struct.hd_geometry, %struct.hd_geometry* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %22)
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
%struct.hd_geometry = type { i32, i32 }
@HDIO_GETGEO = global i32 0
@.str = [74 x i8] c"Using disk geometry of %u heads and %u sectors/track for CHS translation\0A\00"
define i32 @get_disk_geometry(i32 %0, %struct.hd_geometry* %1) {
%3 = load i32, i32* @HDIO_GETGEO
%4 = tail call i64 @ioctl(i32 %0, i32 %3, %struct.hd_geometry* %1)
%5 = icmp eq i64 %4, 0
%6 = getelementptr inbounds %struct.hd_geometry, %struct.hd_geometry* %1, i64 0, i32 0
br i1 %5, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* %6
%9 = getelementptr inbounds %struct.hd_geometry, %struct.hd_geometry* %1, i64 0, i32 1
%10 = load i32, i32* %9
br label %13
11: ; preds = %2
store i32 255, i32* %6
%12 = getelementptr inbounds %struct.hd_geometry, %struct.hd_geometry* %1, i64 0, i32 1
store i32 63, i32* %12
br label %13
13: ; preds = %7, %11
%14 = phi i32 [ %10, %7 ], [ 63, %11 ]
%15 = phi i32 [ %8, %7 ], [ 255, %11 ]
%16 = tail call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %14)
ret i32 1
}