#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*/ check_mp_status(int *);
int /*<<< orphan*/ diskplay_partition_info();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int get_disk_size(unsigned long *);
int /*<<< orphan*/ set_mp_flag();
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ usleep(int);
scalar_t__ write_sector_num_to_p4(unsigned long);
int main(int argc, char **argv) {
  int ret = 0;
  int mp_status = -1;
  unsigned long p4_size = 0;
  if (argc < 2 || !strcmp(argv[1], "-h")) {
    usage();
    exit(0);
  }
  if (!strcmp(argv[1], "read")) {
    diskplay_partition_info();
  } else if (!strcmp(argv[1], "write")) {
    check_mp_status(&mp_status);
    if (mp_status == 0) {
      if (get_disk_size(&p4_size) == 1) {
        if (write_sector_num_to_p4(p4_size) == 0) {
          set_mp_flag();
          usleep(10000);
        }
      }
    }
  } else {
    usage();
  }
  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)
movl   $0x0,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11e3 <main+0x53>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11f1 <main+0x61>
mov    $0x0,%al
call   1090 <usage@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe03(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    121a <main+0x8a>
mov    $0x0,%al
call   1070 <diskplay_partition_info@plt>
jmp    129b <main+0x10b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xddf(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    128f <main+0xff>
lea    -0x18(%rbp),%rdi
call   1050 <check_mp_status@plt>
cmpl   $0x0,-0x18(%rbp)
jne    128a <main+0xfa>
lea    -0x20(%rbp),%rdi
call   1030 <get_disk_size@plt>
cmp    $0x1,%eax
jne    1285 <main+0xf5>
mov    -0x20(%rbp),%rdi
call   1080 <write_sector_num_to_p4@plt>
cmp    $0x0,%rax
jne    1280 <main+0xf0>
mov    $0x0,%al
call   1040 <set_mp_flag@plt>
mov    $0x2710,%edi
call   10b0 <usleep@plt>
jmp    1285 <main+0xf5>
jmp    128a <main+0xfa>
jmp    1296 <main+0x106>
mov    $0x0,%al
call   1090 <usage@plt>
jmp    129b <main+0x10b>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0xffffffff,0x4(%rsp)
ff
movq   $0x0,0x8(%rsp)
cmp    $0x2,%edi
jl     124a <main+0xba>
mov    0x8(%rsi),%rbx
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     124a <main+0xba>
lea    0xe32(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11f9 <main+0x69>
lea    0xe24(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1202 <main+0x72>
xor    %eax,%eax
call   1090 <usage@plt>
jmp    1242 <main+0xb2>
xor    %eax,%eax
call   1070 <diskplay_partition_info@plt>
jmp    1242 <main+0xb2>
lea    0x4(%rsp),%rdi
call   1050 <check_mp_status@plt>
cmpl   $0x0,0x4(%rsp)
jne    1242 <main+0xb2>
lea    0x8(%rsp),%rdi
call   1030 <get_disk_size@plt>
cmp    $0x1,%eax
jne    1242 <main+0xb2>
mov    0x8(%rsp),%rdi
call   1080 <write_sector_num_to_p4@plt>
test   %rax,%rax
jne    1242 <main+0xb2>
xor    %eax,%eax
call   1040 <set_mp_flag@plt>
mov    $0x2710,%edi
call   10b0 <usleep@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
call   1090 <usage@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"-h\00"
@.str.1 = [5 x i8] c"read\00"
@.str.2 = [6 x i8] c"write\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 i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 -1, i32* %7
store i64 0, i64* %8
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %17, label %11
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %11, %2
%18 = call i32 (...) @usage()
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %11
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = call i32 (...) @diskplay_partition_info()
br label %54
28: ; preds = %20
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %51, label %34
34: ; preds = %28
%35 = call i32 @check_mp_status(i32* %7)
%36 = load i32, i32* %7
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %50
38: ; preds = %34
%39 = call i32 @get_disk_size(i64* %8)
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %49
41: ; preds = %38
%42 = load i64, i64* %8
%43 = call i64 @write_sector_num_to_p4(i64 %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = call i32 (...) @set_mp_flag()
%47 = call i32 @usleep(i32 10000)
br label %48
48: ; preds = %45, %41
br label %49
49: ; preds = %48, %38
br label %50
50: ; preds = %49, %34
br label %53
51: ; preds = %28
%52 = call i32 (...) @usage()
br label %53
53: ; preds = %51, %50
br label %54
54: ; preds = %53, %26
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"-h\00"
@.str.1 = [5 x i8] c"read\00"
@.str.2 = [6 x i8] c"write\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i64
%5 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = icmp slt i32 %0, 2
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8, %2
%14 = tail call i32 (...) @usage()
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %8
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 (...) @diskplay_partition_info()
br label %40
21: ; preds = %16
%22 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %38
24: ; preds = %21
%25 = call i32 @check_mp_status(i32* %3)
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %40
28: ; preds = %24
%29 = call i32 @get_disk_size(i64* %4)
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %40
31: ; preds = %28
%32 = load i64, i64* %4
%33 = call i64 @write_sector_num_to_p4(i64 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = call i32 (...) @set_mp_flag()
%37 = call i32 @usleep(i32 10000)
br label %40
38: ; preds = %21
%39 = tail call i32 (...) @usage()
br label %40
40: ; preds = %38, %28, %35, %31, %24, %19
ret i32 0
}