#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;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  int option = 0;
  int area = -1, perimeter = -1, breadth = -1, length = -1;
  while ((option = getopt(argc, argv, "apl:b:")) != -1) {
    switch (option) {
    case 'a':
      area = 0;
      break;
    case 'p':
      perimeter = 0;
      break;
    case 'l':
      length = atoi(optarg);
      break;
    case 'b':
      breadth = atoi(optarg);
      break;
    default:
      print_usage();
      exit(EXIT_FAILURE);
    }
  }
  if (length == -1 || breadth == -1) {
    print_usage();
    exit(EXIT_FAILURE);
  }
  if (area == 0) {
    area = length * breadth;
    printf("Area: %d\n", area);
  }
  if (perimeter == 0) {
    perimeter = 2 * (length + breadth);
    printf("Perimeter: %d\n", perimeter);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xea9(%rip),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     122f <main+0xdf>
mov    -0x14(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0xf,%eax
ja     1215 <main+0xc5>
mov    -0x30(%rbp),%rax
lea    0xe38(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x18(%rbp)
jmp    122a <main+0xda>
movl   $0x0,-0x1c(%rbp)
jmp    122a <main+0xda>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1050 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    122a <main+0xda>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1050 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    122a <main+0xda>
mov    $0x0,%al
call   1070 <print_usage@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    1189 <main+0x39>
cmpl   $0xffffffff,-0x24(%rbp)
je     1243 <main+0xf3>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1258 <main+0x108>
mov    $0x0,%al
call   1070 <print_usage@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
jne    127b <main+0x12b>
mov    -0x24(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xdd1(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    12a0 <main+0x150>
mov    -0x24(%rbp),%eax
add    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xdb6(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %edi,%ebx
movl   $0xffffffff,0x4(%rsp)
ff
movl   $0x0,(%rsp)
lea    0xe8a(%rip),%r12
mov    0x2e7b(%rip),%r13
mov    $0xffffffff,%r14d
mov    $0xffffffff,%r15d
jmp    119c <main+0x4c>
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
call   1050 <atoi@plt>
mov    %eax,%r15d
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1040 <getopt@plt>
cmp    $0x6c,%eax
je     1190 <main+0x40>
cmp    $0x61,%eax
jg     11c4 <main+0x74>
cmp    $0xffffffff,%eax
je     11e6 <main+0x96>
cmp    $0x61,%eax
jne    1238 <main+0xe8>
mov    $0x1,%al
mov    %eax,(%rsp)
jmp    119c <main+0x4c>
cmp    $0x62,%eax
je     11d8 <main+0x88>
cmp    $0x70,%eax
jne    1238 <main+0xe8>
movl   $0x0,0x4(%rsp)
jmp    119c <main+0x4c>
mov    0x0(%r13),%edi
call   1050 <atoi@plt>
mov    %eax,%r14d
jmp    119c <main+0x4c>
cmp    $0xffffffff,%r15d
je     1238 <main+0xe8>
cmp    $0xffffffff,%r14d
je     1238 <main+0xe8>
testb  $0x1,(%rsp)
je     120b <main+0xbb>
mov    %r15d,%esi
imul   %r14d,%esi
lea    0xe01(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jne    1227 <main+0xd7>
add    %r14d,%r15d
add    %r15d,%r15d
lea    0xdf2(%rip),%rdi
mov    %r15d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1070 <print_usage@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"apl:b:\00"
@optarg = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [10 x i8] c"Area: %d\0A\00"
@.str.2 = [15 x i8] c"Perimeter: %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
%10 = alloca i32
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 i32 -1, i32* %8
store i32 -1, i32* %9
store i32 -1, i32* %10
br label %11
11: ; preds = %30, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %6
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %31
16: ; preds = %11
%17 = load i32, i32* %6
switch i32 %17, label %26 [
i32 97, label %18
i32 112, label %19
i32 108, label %20
i32 98, label %23
]
18: ; preds = %16
store i32 0, i32* %7
br label %30
19: ; preds = %16
store i32 0, i32* %8
br label %30
20: ; preds = %16
%21 = load i32, i32* @optarg
%22 = call i32 @atoi(i32 %21)
store i32 %22, i32* %10
br label %30
23: ; preds = %16
%24 = load i32, i32* @optarg
%25 = call i32 @atoi(i32 %24)
store i32 %25, i32* %9
br label %30
26: ; preds = %16
%27 = call i32 (...) @print_usage()
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %23, %20, %19, %18
br label %11
31: ; preds = %11
%32 = load i32, i32* %10
%33 = icmp eq i32 %32, -1
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i32, i32* %9
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %41
37: ; preds = %34, %31
%38 = call i32 (...) @print_usage()
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %34
%42 = load i32, i32* %7
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %41
%45 = load i32, i32* %10
%46 = load i32, i32* %9
%47 = mul nsw i32 %45, %46
store i32 %47, i32* %7
%48 = load i32, i32* %7
%49 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %44, %41
%51 = load i32, i32* %8
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %60
53: ; preds = %50
%54 = load i32, i32* %10
%55 = load i32, i32* %9
%56 = add nsw i32 %54, %55
%57 = mul nsw i32 2, %56
store i32 %57, i32* %8
%58 = load i32, i32* %8
%59 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %53, %50
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"apl:b:\00"
@optarg = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [10 x i8] c"Area: %d\0A\00"
@.str.2 = [15 x i8] c"Perimeter: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %15, %2
%4 = phi i1 [ false, %2 ], [ true, %15 ]
%5 = phi i32 [ -1, %2 ], [ %9, %15 ]
%6 = phi i32 [ -1, %2 ], [ %13, %15 ]
%7 = phi i32 [ -1, %2 ], [ %16, %15 ]
br label %8
8: ; preds = %15, %3
%9 = phi i32 [ %5, %3 ], [ 0, %15 ]
%10 = phi i32 [ %6, %3 ], [ %13, %15 ]
%11 = phi i32 [ %7, %3 ], [ %16, %15 ]
br label %12
12: ; preds = %8, %21
%13 = phi i32 [ %10, %8 ], [ %23, %21 ]
%14 = phi i32 [ %11, %8 ], [ %16, %21 ]
br label %15
15: ; preds = %12, %18
%16 = phi i32 [ %20, %18 ], [ %14, %12 ]
%17 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
switch i32 %17, label %24 [
i32 -1, label %28
i32 97, label %3
i32 112, label %8
i32 108, label %18
i32 98, label %21
]
18: ; preds = %15
%19 = load i32, i32* @optarg
%20 = tail call i32 @atoi(i32 %19)
br label %15
21: ; preds = %15
%22 = load i32, i32* @optarg
%23 = tail call i32 @atoi(i32 %22)
br label %12
24: ; preds = %15
%25 = tail call i32 (...) @print_usage()
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %15
%29 = icmp eq i32 %16, -1
%30 = icmp eq i32 %13, -1
%31 = select i1 %29, i1 true, i1 %30
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = tail call i32 (...) @print_usage()
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %28
br i1 %4, label %37, label %40
37: ; preds = %36
%38 = mul nsw i32 %16, %13
%39 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %37, %36
%41 = icmp eq i32 %9, 0
br i1 %41, label %42, label %46
42: ; preds = %40
%43 = add nsw i32 %16, %13
%44 = shl nsw i32 %43, 1
%45 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %42, %40
ret i32 0
}