#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(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int getopt(int, char **, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ optarg;
int optopt;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int c, i;
  int space = 0;
  int nmsgs = 5;
  int nmsgstart = 0;
  int nchars = -1;
  int errflg = 0;
  char *extradata = NULL;
  while ((c = getopt(argc, argv, "pm:i:d:")) != -1) {
    switch (c) {
    case 'm':
      nmsgs = atoi(optarg);
      break;
    case 'i':
      nmsgstart = atoi(optarg);
      break;
    case 'd':
      nchars = atoi(optarg);
      break;
    case 'p':
      space = 1;
      break;
    case ':':
      fprintf(stderr, "Option -%c requires an operand\n", optopt);
      errflg++;
      break;
    case '?':
      fprintf(stderr, "Unrecognized option: -%c\n", optopt);
      errflg++;
      break;
    }
  }
  if (errflg) {
    fprintf(stderr, "Usage: -m <nmsgs> -d <nchars> -p\n");
    exit(2);
  }
  if (nchars != -1) {
    extradata = (char *)malloc(nchars + 1);
    memset(extradata, 'X', nchars);
    extradata[nchars] = '\0';
  }
  for (i = nmsgstart; i < (nmsgs + nmsgstart); ++i) {
    printf("msgnum:%8.8d:", i);
    if (space == 1) {
      printf("\n ");
    }
    if (nchars != -1) {
      printf("%s", extradata);
    }
    printf("\n");
  }
  free(extradata);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x5,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0xffffffff,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xf0d(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12b3 <main+0x133>
mov    -0x14(%rbp),%eax
add    $0xffffffc6,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x36,%eax
ja     12ae <main+0x12e>
mov    -0x40(%rbp),%rax
lea    0xe00(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    12ae <main+0x12e>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    12ae <main+0x12e>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %eax,-0x28(%rbp)
jmp    12ae <main+0x12e>
movl   $0x1,-0x1c(%rbp)
jmp    12ae <main+0x12e>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
mov    0x2d79(%rip),%rax
mov    (%rax),%edx
lea    0xe74(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12ae <main+0x12e>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
mov    0x2d4b(%rip),%rax
mov    (%rax),%edx
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c1 <main+0x41>
cmpl   $0x0,-0x2c(%rbp)
je     12de <main+0x15e>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
cmpl   $0xffffffff,-0x28(%rbp)
je     1314 <main+0x194>
mov    -0x28(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    $0x58,%esi
call   1050 <memset@plt>
mov    -0x38(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x20(%rbp),%ecx
add    -0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    138c <main+0x20c>
mov    -0x18(%rbp),%esi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x1c(%rbp)
jne    1354 <main+0x1d4>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0xffffffff,-0x28(%rbp)
je     1370 <main+0x1f0>
mov    -0x38(%rbp),%rsi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    131a <main+0x19a>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %edi,%ebx
mov    $0xffffffff,%r15d
movl   $0x5,0x10(%rsp)
lea    0xf24(%rip),%r13
lea    0xe41(%rip),%r14
movl   $0x0,0x14(%rsp)
xor    %ebp,%ebp
movl   $0x0,0xc(%rsp)
jmp    11e9 <main+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0xffffffff,%eax
je     1293 <main+0x103>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1090 <getopt@plt>
lea    -0x3a(%rax),%ecx
cmp    $0x36,%ecx
ja     11e0 <main+0x50>
movslq (%r14,%rcx,4),%rax
add    %r14,%rax
jmp    *%rax
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%edx
lea    0xec4(%rip),%rsi
jmp    123b <main+0xab>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    0x2dae(%rip),%rax
mov    (%rax),%edx
lea    0xec9(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
addl   $0x1,0xc(%rsp)
jmp    11e9 <main+0x59>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,%r15d
jmp    11e9 <main+0x59>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,%ebp
jmp    11e9 <main+0x59>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,0x10(%rsp)
jmp    11e9 <main+0x59>
mov    $0x1,%al
mov    %eax,0x14(%rsp)
jmp    11e9 <main+0x59>
cmpl   $0x0,0xc(%rsp)
jne    1350 <main+0x1c0>
cmp    $0xffffffff,%r15d
mov    0x10(%rsp),%ebx
je     12d2 <main+0x142>
lea    0x1(%r15),%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x58,%esi
mov    %r15d,%edx
call   1060 <memset@plt>
movslq %r15d,%rax
movb   $0x0,(%r14,%rax,1)
test   %ebx,%ebx
jg     12d9 <main+0x149>
jmp    1337 <main+0x1a7>
xor    %r14d,%r14d
test   %ebx,%ebx
jle    1337 <main+0x1a7>
add    %ebp,%ebx
lea    0xe5e(%rip),%r12
lea    0xe68(%rip),%r13
jmp    1301 <main+0x171>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x1,%ebp
cmp    %ebx,%ebp
jge    1337 <main+0x1a7>
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
testb  $0x1,0x14(%rsp)
je     1322 <main+0x192>
lea    0xe33(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0xffffffff,%r15d
je     12f0 <main+0x160>
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12f0 <main+0x160>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c79(%rip),%rax
mov    (%rax),%edi
lea    0xdbe(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"pm:i:d:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"Option -%c requires an operand\0A\00"
@optopt = global i32 0
@.str.2 = [26 x i8] c"Unrecognized option: -%c\0A\00"
@.str.3 = [34 x i8] c"Usage: -m <nmsgs> -d <nchars> -p\0A\00"
@.str.4 = [14 x i8] c"msgnum:%8.8d:\00"
@.str.5 = [3 x i8] c"\0A \00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [2 x i8] c"\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
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 5, i32* %9
store i32 0, i32* %10
store i32 -1, i32* %11
store i32 0, i32* %12
store i8* null, i8** %13
br label %14
14: ; preds = %43, %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 %17, i32* %6
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %44
19: ; preds = %14
%20 = load i32, i32* %6
switch i32 %20, label %43 [
i32 109, label %21
i32 105, label %24
i32 100, label %27
i32 112, label %30
i32 58, label %31
i32 63, label %37
]
21: ; preds = %19
%22 = load i32, i32* @optarg
%23 = call i32 @atoi(i32 %22)
store i32 %23, i32* %9
br label %43
24: ; preds = %19
%25 = load i32, i32* @optarg
%26 = call i32 @atoi(i32 %25)
store i32 %26, i32* %10
br label %43
27: ; preds = %19
%28 = load i32, i32* @optarg
%29 = call i32 @atoi(i32 %28)
store i32 %29, i32* %11
br label %43
30: ; preds = %19
store i32 1, i32* %8
br label %43
31: ; preds = %19
%32 = load i32, i32* @stderr
%33 = load i32, i32* @optopt
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %12
%36 = add nsw i32 %35, 1
store i32 %36, i32* %12
br label %43
37: ; preds = %19
%38 = load i32, i32* @stderr
%39 = load i32, i32* @optopt
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %12
%42 = add nsw i32 %41, 1
store i32 %42, i32* %12
br label %43
43: ; preds = %19, %37, %31, %30, %27, %24, %21
br label %14
44: ; preds = %14
%45 = load i32, i32* %12
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%50 = call i32 @exit(i32 2)
unreachable
51: ; preds = %44
%52 = load i32, i32* %11
%53 = icmp ne i32 %52, -1
br i1 %53, label %54, label %66
54: ; preds = %51
%55 = load i32, i32* %11
%56 = add nsw i32 %55, 1
%57 = call i64 @malloc(i32 %56)
%58 = inttoptr i64 %57 to i8*
store i8* %58, i8** %13
%59 = load i8*, i8** %13
%60 = load i32, i32* %11
%61 = call i32 @memset(i8* %59, i8 signext 88, i32 %60)
%62 = load i8*, i8** %13
%63 = load i32, i32* %11
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
store i8 0, i8* %65
br label %66
66: ; preds = %54, %51
%67 = load i32, i32* %10
store i32 %67, i32* %7
br label %68
68: ; preds = %89, %66
%69 = load i32, i32* %7
%70 = load i32, i32* %9
%71 = load i32, i32* %10
%72 = add nsw i32 %70, %71
%73 = icmp slt i32 %69, %72
br i1 %73, label %74, label %92
74: ; preds = %68
%75 = load i32, i32* %7
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %75)
%77 = load i32, i32* %8
%78 = icmp eq i32 %77, 1
br i1 %78, label %79, label %81
79: ; preds = %74
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %81
81: ; preds = %79, %74
%82 = load i32, i32* %11
%83 = icmp ne i32 %82, -1
br i1 %83, label %84, label %87
84: ; preds = %81
%85 = load i8*, i8** %13
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %85)
br label %87
87: ; preds = %84, %81
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %89
89: ; preds = %87
%90 = load i32, i32* %7
%91 = add nsw i32 %90, 1
store i32 %91, i32* %7
br label %68
92: ; preds = %68
%93 = load i8*, i8** %13
%94 = call i32 @free(i8* %93)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"pm:i:d:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"Option -%c requires an operand\0A\00"
@optopt = global i32 0
@.str.2 = [26 x i8] c"Unrecognized option: -%c\0A\00"
@.str.3 = [34 x i8] c"Usage: -m <nmsgs> -d <nchars> -p\0A\00"
@.str.4 = [14 x i8] c"msgnum:%8.8d:\00"
@.str.5 = [3 x i8] c"\0A \00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %23, %2
%4 = phi i1 [ false, %2 ], [ true, %23 ]
%5 = phi i32 [ 5, %2 ], [ %10, %23 ]
%6 = phi i32 [ 0, %2 ], [ %15, %23 ]
%7 = phi i32 [ -1, %2 ], [ %19, %23 ]
%8 = phi i32 [ 0, %2 ], [ %22, %23 ]
br label %9
9: ; preds = %3, %25
%10 = phi i32 [ %5, %3 ], [ %27, %25 ]
%11 = phi i32 [ %6, %3 ], [ %15, %25 ]
%12 = phi i32 [ %7, %3 ], [ %19, %25 ]
%13 = phi i32 [ %8, %3 ], [ %22, %25 ]
br label %14
14: ; preds = %9, %28
%15 = phi i32 [ %11, %9 ], [ %30, %28 ]
%16 = phi i32 [ %12, %9 ], [ %19, %28 ]
%17 = phi i32 [ %13, %9 ], [ %22, %28 ]
br label %18
18: ; preds = %14, %31
%19 = phi i32 [ %16, %14 ], [ %33, %31 ]
%20 = phi i32 [ %17, %14 ], [ %22, %31 ]
br label %21
21: ; preds = %42, %18
%22 = phi i32 [ %20, %18 ], [ %43, %42 ]
br label %23
23: ; preds = %21, %23
%24 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
switch i32 %24, label %23 [
i32 -1, label %44
i32 109, label %25
i32 105, label %28
i32 100, label %31
i32 112, label %3
i32 58, label %34
i32 63, label %38
]
25: ; preds = %23
%26 = load i32, i32* @optarg
%27 = tail call i32 @atoi(i32 %26)
br label %9
28: ; preds = %23
%29 = load i32, i32* @optarg
%30 = tail call i32 @atoi(i32 %29)
br label %14
31: ; preds = %23
%32 = load i32, i32* @optarg
%33 = tail call i32 @atoi(i32 %32)
br label %18
34: ; preds = %23
%35 = load i32, i32* @stderr
%36 = load i32, i32* @optopt
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %42
38: ; preds = %23
%39 = load i32, i32* @stderr
%40 = load i32, i32* @optopt
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %38, %34
%43 = add nsw i32 %22, 1
br label %21
44: ; preds = %23
%45 = icmp eq i32 %22, 0
br i1 %45, label %50, label %46
46: ; preds = %44
%47 = load i32, i32* @stderr
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%49 = tail call i32 @exit(i32 2)
unreachable
50: ; preds = %44
%51 = icmp eq i32 %19, -1
br i1 %51, label %59, label %52
52: ; preds = %50
%53 = add nuw nsw i32 %19, 1
%54 = tail call i64 @malloc(i32 %53)
%55 = inttoptr i64 %54 to i8*
%56 = tail call i32 @memset(i8* %55, i8 signext 88, i32 %19)
%57 = sext i32 %19 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 0, i8* %58
br label %59
59: ; preds = %52, %50
%60 = phi i8* [ %55, %52 ], [ null, %50 ]
%61 = add nsw i32 %15, %10
%62 = icmp sgt i32 %10, 0
br i1 %62, label %63, label %75
63: ; preds = %59, %71
%64 = phi i32 [ %73, %71 ], [ %15, %59 ]
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %64)
br i1 %4, label %66, label %68
66: ; preds = %63
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %68
68: ; preds = %66, %63
br i1 %51, label %71, label %69
69: ; preds = %68
%70 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %60)
br label %71
71: ; preds = %69, %68
%72 = tail call i32 @putchar(i32 10)
%73 = add nsw i32 %64, 1
%74 = icmp slt i32 %73, %61
br i1 %74, label %63, label %75
75: ; preds = %71, %59
%76 = tail call i32 @free(i8* %60)
ret i32 0
}