#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 nchars = -1;
  int errflg = 0;
  char *extradata = NULL;
  while ((c = getopt(argc, argv, "pm:d:")) != -1) {
    switch (c) {
    case 'm':
      nmsgs = 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 = 0; i < nmsgs; ++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   $0xffffffff,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe38(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12c5 <main+0x145>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x3a,%eax
je     1269 <main+0xe9>
jmp    11ed <main+0x6d>
mov    -0x34(%rbp),%eax
sub    $0x3f,%eax
je     1297 <main+0x117>
jmp    11fe <main+0x7e>
mov    -0x34(%rbp),%eax
sub    $0x64,%eax
je     1247 <main+0xc7>
jmp    120f <main+0x8f>
mov    -0x34(%rbp),%eax
sub    $0x6d,%eax
je     1231 <main+0xb1>
jmp    1220 <main+0xa0>
mov    -0x34(%rbp),%eax
sub    $0x70,%eax
je     125d <main+0xdd>
jmp    12c0 <main+0x140>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    12c0 <main+0x140>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    12c0 <main+0x140>
movl   $0x1,-0x1c(%rbp)
jmp    12c0 <main+0x140>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
mov    0x2d67(%rip),%rax
mov    (%rax),%edx
lea    0xd84(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12c0 <main+0x140>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
mov    0x2d39(%rip),%rax
mov    (%rax),%edx
lea    0xd76(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ba <main+0x3a>
cmpl   $0x0,-0x28(%rbp)
je     12f0 <main+0x170>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
lea    0xd61(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
cmpl   $0xffffffff,-0x24(%rbp)
je     1326 <main+0x1a6>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    $0x58,%esi
call   1050 <memset@plt>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    139a <main+0x21a>
mov    -0x18(%rbp),%esi
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x1c(%rbp)
jne    1362 <main+0x1e2>
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0xffffffff,-0x24(%rbp)
je     137e <main+0x1fe>
mov    -0x30(%rbp),%rsi
lea    0xcfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xcb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    132d <main+0x1ad>
mov    -0x30(%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
push   %rax
mov    %rsi,%rbp
mov    %edi,%ebx
mov    $0xffffffff,%r15d
mov    $0x5,%r14d
lea    0xe4d(%rip),%r12
xor    %r13d,%r13d
movl   $0x0,0x4(%rsp)
xchg   %ax,%ax
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1090 <getopt@plt>
cmp    $0x63,%eax
jg     1200 <main+0x70>
cmp    $0xffffffff,%eax
je     1267 <main+0xd7>
cmp    $0x3a,%eax
je     1235 <main+0xa5>
cmp    $0x3f,%eax
jne    11c0 <main+0x30>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    0x2deb(%rip),%rax
mov    (%rax),%edx
lea    0xe28(%rip),%rsi
jmp    124e <main+0xbe>
cmp    $0x64,%eax
je     1222 <main+0x92>
cmp    $0x70,%eax
je     125f <main+0xcf>
cmp    $0x6d,%eax
jne    11c0 <main+0x30>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,%r14d
jmp    11c0 <main+0x30>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,%r15d
jmp    11c0 <main+0x30>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
mov    0x2d9b(%rip),%rax
mov    (%rax),%edx
lea    0xdb8(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
addl   $0x1,0x4(%rsp)
jmp    11c0 <main+0x30>
mov    $0x1,%r13b
jmp    11c0 <main+0x30>
cmpl   $0x0,0x4(%rsp)
jne    1326 <main+0x196>
cmp    $0xffffffff,%r15d
je     12a2 <main+0x112>
lea    0x1(%r15),%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x58,%esi
mov    %r15d,%edx
call   1060 <memset@plt>
movslq %r15d,%rax
movb   $0x0,(%rbx,%rax,1)
test   %r14d,%r14d
jg     12a9 <main+0x119>
jmp    130d <main+0x17d>
xor    %ebx,%ebx
test   %r14d,%r14d
jle    130d <main+0x17d>
lea    0xdb2(%rip),%rbp
xor    %r12d,%r12d
jmp    12d3 <main+0x143>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x1,%r12d
cmp    %r12d,%r14d
je     130d <main+0x17d>
mov    %rbp,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   $0x1,%r13b
je     12f4 <main+0x164>
lea    0xd83(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0xffffffff,%r15d
je     12c0 <main+0x130>
lea    0xd72(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12c0 <main+0x130>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
lea    0xd0a(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>

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

LLVM IR (-O2):
@.str = [6 x i8] c"pm: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 = %17, %2
%4 = phi i1 [ false, %2 ], [ true, %17 ]
%5 = phi i32 [ 5, %2 ], [ %9, %17 ]
%6 = phi i32 [ -1, %2 ], [ %13, %17 ]
%7 = phi i32 [ 0, %2 ], [ %16, %17 ]
br label %8
8: ; preds = %3, %19
%9 = phi i32 [ %5, %3 ], [ %21, %19 ]
%10 = phi i32 [ %6, %3 ], [ %13, %19 ]
%11 = phi i32 [ %7, %3 ], [ %16, %19 ]
br label %12
12: ; preds = %8, %22
%13 = phi i32 [ %10, %8 ], [ %24, %22 ]
%14 = phi i32 [ %11, %8 ], [ %16, %22 ]
br label %15
15: ; preds = %33, %12
%16 = phi i32 [ %14, %12 ], [ %34, %33 ]
br label %17
17: ; preds = %15, %17
%18 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
switch i32 %18, label %17 [
i32 -1, label %35
i32 109, label %19
i32 100, label %22
i32 112, label %3
i32 58, label %25
i32 63, label %29
]
19: ; preds = %17
%20 = load i32, i32* @optarg
%21 = tail call i32 @atoi(i32 %20)
br label %8
22: ; preds = %17
%23 = load i32, i32* @optarg
%24 = tail call i32 @atoi(i32 %23)
br label %12
25: ; preds = %17
%26 = load i32, i32* @stderr
%27 = load i32, i32* @optopt
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %33
29: ; preds = %17
%30 = load i32, i32* @stderr
%31 = load i32, i32* @optopt
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %29, %25
%34 = add nsw i32 %16, 1
br label %15
35: ; preds = %17
%36 = icmp eq i32 %16, 0
br i1 %36, label %41, label %37
37: ; preds = %35
%38 = load i32, i32* @stderr
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%40 = tail call i32 @exit(i32 2)
unreachable
41: ; preds = %35
%42 = icmp eq i32 %13, -1
br i1 %42, label %50, label %43
43: ; preds = %41
%44 = add nuw nsw i32 %13, 1
%45 = tail call i64 @malloc(i32 %44)
%46 = inttoptr i64 %45 to i8*
%47 = tail call i32 @memset(i8* %46, i8 signext 88, i32 %13)
%48 = sext i32 %13 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
br label %50
50: ; preds = %43, %41
%51 = phi i8* [ %46, %43 ], [ null, %41 ]
%52 = icmp sgt i32 %9, 0
br i1 %52, label %53, label %65
53: ; preds = %50, %61
%54 = phi i32 [ %63, %61 ], [ 0, %50 ]
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %54)
br i1 %4, label %56, label %58
56: ; preds = %53
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %58
58: ; preds = %56, %53
br i1 %42, label %61, label %59
59: ; preds = %58
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %51)
br label %61
61: ; preds = %59, %58
%62 = tail call i32 @putchar(i32 10)
%63 = add nuw nsw i32 %54, 1
%64 = icmp eq i32 %63, %9
br i1 %64, label %65, label %53
65: ; preds = %61, %50
%66 = tail call i32 @free(i8* %51)
ret i32 0
}