#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(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int extradata = 0;
  char *pdata = "";
  int nmsgs;
  int i;
  if (argc < 2 && argc > 3) {
    fprintf(stderr, "usage: inputfilegen num-messages [extra-data]\n");
    return 1;
  }
  nmsgs = atoi(argv[1]);
  if (argc == 3) {
    extradata = atoi(argv[2]);
    if ((pdata = malloc(extradata + 1)) == NULL) {
      perror("malloc extradata");
      return 2;
    }
    memset(pdata, 'X', extradata);
    pdata[extradata] = '\0';
  }
  for (i = 0; i < nmsgs; ++i) {
    printf("msgnum:%8.8d:%s\n", i, pdata);
  }
  if (argc == 3)
    free(pdata);
  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)
lea    0xe9a(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11cd <main+0x5d>
cmpl   $0x3,-0x8(%rbp)
jle    11cd <main+0x5d>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1293 <main+0x123>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1245 <main+0xd5>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1228 <main+0xb8>
lea    0xe18(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1293 <main+0x123>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x58,%esi
call   1050 <memset@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1279 <main+0x109>
mov    -0x28(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xdda(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    124c <main+0xdc>
cmpl   $0x3,-0x8(%rbp)
jne    128c <main+0x11c>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r12d
cmp    $0x3,%r14d
jne    11bb <main+0x5b>
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
lea    0x1(%r15),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1200 <main+0xa0>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x58,%esi
mov    %r15d,%edx
call   1050 <memset@plt>
movslq %r15d,%rax
movb   $0x0,(%rbx,%rax,1)
test   %r12d,%r12d
jg     11c7 <main+0x67>
jmp    11e5 <main+0x85>
lea    0xe5f(%rip),%rbx
test   %r12d,%r12d
jle    11e5 <main+0x85>
xor    %ebp,%ebp
lea    0xe41(%rip),%r15
mov    %r15,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    %ebp,%r12d
jne    11d0 <main+0x70>
xor    %ebp,%ebp
cmp    $0x3,%r14d
jne    11f5 <main+0x95>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf9(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%ebp
jmp    11f5 <main+0x95>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [47 x i8] c"usage: inputfilegen num-messages [extra-data]\0A\00"
@.str.2 = [17 x i8] c"malloc extradata\00"
@.str.3 = [17 x i8] c"msgnum:%8.8d:%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %7
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 3
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %63
18: ; preds = %12, %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %8
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 3
br i1 %24, label %25, label %44
25: ; preds = %18
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
%32 = call i8* @malloc(i32 %31)
store i8* %32, i8** %7
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %36
34: ; preds = %25
%35 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %63
36: ; preds = %25
%37 = load i8*, i8** %7
%38 = load i32, i32* %6
%39 = call i32 @memset(i8* %37, i8 signext 88, i32 %38)
%40 = load i8*, i8** %7
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 0, i8* %43
br label %44
44: ; preds = %36, %18
store i32 0, i32* %9
br label %45
45: ; preds = %53, %44
%46 = load i32, i32* %9
%47 = load i32, i32* %8
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %56
49: ; preds = %45
%50 = load i32, i32* %9
%51 = load i8*, i8** %7
%52 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %50, i8* %51)
br label %53
53: ; preds = %49
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %9
br label %45
56: ; preds = %45
%57 = load i32, i32* %4
%58 = icmp eq i32 %57, 3
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i8*, i8** %7
%61 = call i32 @free(i8* %60)
br label %62
62: ; preds = %59, %56
store i32 0, i32* %3
br label %63
63: ; preds = %62, %34, %15
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.2 = [17 x i8] c"malloc extradata\00"
@.str.3 = [17 x i8] c"msgnum:%8.8d:%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = icmp eq i32 %0, 3
br i1 %6, label %7, label %20
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = add nsw i32 %10, 1
%12 = tail call i8* @malloc(i32 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %7
%15 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %31
16: ; preds = %7
%17 = tail call i32 @memset(i8* %12, i8 signext 88, i32 %10)
%18 = sext i32 %10 to i64
%19 = getelementptr inbounds i8, i8* %12, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %16, %2
%21 = phi i8* [ %12, %16 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ]
%22 = icmp sgt i32 %5, 0
br i1 %22, label %23, label %28
23: ; preds = %20, %23
%24 = phi i32 [ %26, %23 ], [ 0, %20 ]
%25 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %24, i8* %21)
%26 = add nuw nsw i32 %24, 1
%27 = icmp eq i32 %26, %5
br i1 %27, label %28, label %23
28: ; preds = %23, %20
br i1 %6, label %29, label %31
29: ; preds = %28
%30 = tail call i32 @free(i8* %21)
br label %31
31: ; preds = %28, %29, %14
%32 = phi i32 [ 2, %14 ], [ 0, %29 ], [ 0, %28 ]
ret i32 %32
}