#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*/ EXIT_FAILURE;
unsigned int atoi(char *);
scalar_t__ check_cs(unsigned int, unsigned int);
int /*<<< orphan*/ check_disk();
int /*<<< orphan*/ dump(unsigned char *, unsigned int, int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ init_master();
int /*<<< orphan*/ read_sector_n(unsigned int, unsigned int, unsigned char *,
                                 unsigned int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  unsigned int c, s, n;
  unsigned char buffer[512];
  if (argc < 3 || argc > 4) {
    fprintf(stderr, "Usage: %s numcylindre numsector [size] \n", argv[0]);
    exit(EXIT_FAILURE);
  } else {
    init_master();
    check_disk();
    c = atoi(argv[1]);
    s = atoi(argv[2]);
    if (check_cs(c, s)) {
      n = 512;
      if (argc == 4) {
        n = atoi(argv[3]);
        n = n < 512 ? n : 512;
      }
      read_sector_n(c, s, buffer, n);
      dump(buffer, n, 1, 1);
    } else {
      if (c >= 1024)
        fprintf(stderr, "Cylindre demandee : %u, max : %i\n", c, 1024 - 1);
      if (s >= 32)
        fprintf(stderr, "Secteur demandee : %u, max : %i\n", s, 32 - 1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     11ad <main+0x2d>
cmpl   $0x4,-0x8(%rbp)
jle    11d9 <main+0x59>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1030 <init_master@plt>
mov    $0x0,%al
call   1040 <check_disk@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1080 <check_cs@plt>
cmp    $0x0,%rax
je     12a1 <main+0x121>
movl   $0x200,-0x1c(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    1271 <main+0xf1>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x200,-0x1c(%rbp)
jae    1258 <main+0xd8>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x224(%rbp)
jmp    1268 <main+0xe8>
mov    $0x200,%eax
mov    %eax,-0x224(%rbp)
jmp    1268 <main+0xe8>
mov    -0x224(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
lea    -0x220(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1070 <read_sector_n@plt>
lea    -0x220(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%ecx
mov    %ecx,%edx
call   1050 <dump@plt>
jmp    12fb <main+0x17b>
cmpl   $0x400,-0x14(%rbp)
jb     12cd <main+0x14d>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xd68(%rip),%rsi
mov    $0x3ff,%ecx
mov    $0x0,%al
call   1060 <fprintf@plt>
cmpl   $0x20,-0x18(%rbp)
jb     12f6 <main+0x176>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xd61(%rip),%rsi
mov    $0x1f,%ecx
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12fb <main+0x17b>
jmp    1300 <main+0x180>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%rbx
mov    %edi,%r15d
lea    -0x5(%r15),%eax
cmp    $0xfffffffd,%eax
jbe    1280 <main+0x100>
xor    %eax,%eax
call   1030 <init_master@plt>
xor    %eax,%eax
call   1040 <check_disk@plt>
mov    0x8(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r12d
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
mov    %r12d,%edi
mov    %eax,%esi
call   1080 <check_cs@plt>
test   %rax,%rax
je     1221 <main+0xa1>
mov    $0x200,%ebp
cmp    $0x4,%r15d
jne    11f8 <main+0x78>
mov    0x18(%rbx),%rdi
call   1090 <atoi@plt>
cmp    $0x200,%eax
mov    $0x200,%ebp
cmovb  %eax,%ebp
mov    %rsp,%rbx
mov    %r12d,%edi
mov    %r14d,%esi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1070 <read_sector_n@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
call   1050 <dump@plt>
jmp    126e <main+0xee>
cmp    $0x400,%r12d
jb     1249 <main+0xc9>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
mov    %r12d,%edx
mov    $0x3ff,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
cmp    $0x20,%r14d
jb     126e <main+0xee>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
mov    %r14d,%edx
mov    $0x1f,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd6d(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"Usage: %s numcylindre numsector [size] \0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [34 x i8] c"Cylindre demandee : %u, max : %i\0A\00"
@.str.2 = [33 x i8] c"Secteur demandee : %u, max : %i\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 [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 4
br i1 %14, label %15, label %23
15: ; preds = %12, %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %12
%24 = call i32 (...) @init_master()
%25 = call i32 (...) @check_disk()
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %6
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %7
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = call i64 @check_cs(i32 %34, i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %62
38: ; preds = %23
store i32 512, i32* %8
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, 4
br i1 %40, label %41, label %53
41: ; preds = %38
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 3
%44 = load i8*, i8** %43
%45 = call i32 @atoi(i8* %44)
store i32 %45, i32* %8
%46 = load i32, i32* %8
%47 = icmp ult i32 %46, 512
br i1 %47, label %48, label %50
48: ; preds = %41
%49 = load i32, i32* %8
br label %51
50: ; preds = %41
br label %51
51: ; preds = %50, %48
%52 = phi i32 [ %49, %48 ], [ 512, %50 ]
store i32 %52, i32* %8
br label %53
53: ; preds = %51, %38
%54 = load i32, i32* %6
%55 = load i32, i32* %7
%56 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%57 = load i32, i32* %8
%58 = call i32 @read_sector_n(i32 %54, i32 %55, i8* %56, i32 %57)
%59 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%60 = load i32, i32* %8
%61 = call i32 @dump(i8* %59, i32 %60, i32 1, i32 1)
br label %77
62: ; preds = %23
%63 = load i32, i32* %6
%64 = icmp uge i32 %63, 1024
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = load i32, i32* @stderr
%67 = load i32, i32* %6
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %67, i32 1023)
br label %69
69: ; preds = %65, %62
%70 = load i32, i32* %7
%71 = icmp uge i32 %70, 32
br i1 %71, label %72, label %76
72: ; preds = %69
%73 = load i32, i32* @stderr
%74 = load i32, i32* %7
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %74, i32 31)
br label %76
76: ; preds = %72, %69
br label %77
77: ; preds = %76, %53
br label %78
78: ; preds = %77
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"Usage: %s numcylindre numsector [size] \0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [34 x i8] c"Cylindre demandee : %u, max : %i\0A\00"
@.str.2 = [33 x i8] c"Secteur demandee : %u, max : %i\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = add i32 %0, -5
%6 = icmp ult i32 %5, -2
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = tail call i32 (...) @init_master()
%15 = tail call i32 (...) @check_disk()
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = tail call i64 @check_cs(i32 %18, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %36, label %24
24: ; preds = %13
%25 = icmp eq i32 %0, 4
br i1 %25, label %26, label %32
26: ; preds = %24
%27 = getelementptr inbounds i8*, i8** %1, i64 3
%28 = load i8*, i8** %27
%29 = tail call i32 @atoi(i8* %28)
%30 = icmp ult i32 %29, 512
%31 = select i1 %30, i32 %29, i32 512
br label %32
32: ; preds = %26, %24
%33 = phi i32 [ %31, %26 ], [ 512, %24 ]
%34 = call i32 @read_sector_n(i32 %18, i32 %21, i8* %4, i32 %33)
%35 = call i32 @dump(i8* %4, i32 %33, i32 1, i32 1)
br label %46
36: ; preds = %13
%37 = icmp ugt i32 %18, 1023
br i1 %37, label %38, label %41
38: ; preds = %36
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 1023)
br label %41
41: ; preds = %38, %36
%42 = icmp ugt i32 %21, 31
br i1 %42, label %43, label %46
43: ; preds = %41
%44 = load i32, i32* @stderr
%45 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 31)
br label %46
46: ; preds = %32, %43, %41
ret i32 0
}