#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ next_num(char **, char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  int rc = 0, iterations = 10, i = 0, l = 0;
  char *num = NULL;
  if (argc < 2) {
    usage(argv[0]);
    rc = 1;
    goto cleanup;
  }
  num = malloc(sizeof(char) * (int)strlen(argv[1]) + 1);
  num = argv[1];
  if (argc > 2) {
    iterations = atoi(argv[2]);
  }
  printf("%s\n", num);
  for (i = 0, l = iterations; i < l; i++) {
    next_num(&num, num);
    printf("%s\n", num);
  }
cleanup:
  if (num) {
    free(num);
  }
  return rc;
}


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   $0xa,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11cc <main+0x5c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <usage@plt>
movl   $0x1,-0x14(%rbp)
jmp    126d <main+0xfd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1214 <main+0xa4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xde1(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1268 <main+0xf8>
mov    -0x28(%rbp),%rsi
lea    -0x28(%rbp),%rdi
call   1050 <next_num@plt>
mov    -0x28(%rbp),%rsi
lea    0xdab(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1231 <main+0xc1>
jmp    126d <main+0xfd>
cmpq   $0x0,-0x28(%rbp)
je     1281 <main+0x111>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     116e <main+0x1e>
mov    (%rsi),%rdi
call   1060 <usage@plt>
mov    $0x1,%ebp
jmp    11ef <main+0x9f>
mov    0x8(%rsi),%rbx
mov    %rbx,(%rsp)
cmp    $0x2,%edi
jne    1191 <main+0x41>
lea    0xe7e(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    $0xa,%ebp
jmp    11af <main+0x5f>
mov    0x10(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
lea    0xe5d(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
test   %ebp,%ebp
jle    11e0 <main+0x90>
mov    %rsp,%r14
lea    0xe47(%rip),%r15
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <next_num@plt>
mov    (%rsp),%rsi
mov    %r15,%rdi
call   1050 <printf@plt>
mov    (%rsp),%rbx
add    $0xffffffff,%ebp
jne    11c0 <main+0x70>
xor    %ebp,%ebp
test   %rbx,%rbx
je     11ef <main+0x9f>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 10, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i8* null, i8** %10
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @usage(i8* %16)
store i32 1, i32* %6
br label %56
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @strlen(i8* %21)
%23 = trunc i64 %22 to i32
%24 = sext i32 %23 to i64
%25 = mul i64 1, %24
%26 = add i64 %25, 1
%27 = trunc i64 %26 to i32
%28 = call i8* @malloc(i32 %27)
store i8* %28, i8** %10
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
store i8* %31, i8** %10
%32 = load i32, i32* %4
%33 = icmp sgt i32 %32, 2
br i1 %33, label %34, label %39
34: ; preds = %18
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
store i32 %38, i32* %7
br label %39
39: ; preds = %34, %18
%40 = load i8*, i8** %10
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %40)
store i32 0, i32* %8
%42 = load i32, i32* %7
store i32 %42, i32* %9
br label %43
43: ; preds = %52, %39
%44 = load i32, i32* %8
%45 = load i32, i32* %9
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %55
47: ; preds = %43
%48 = load i8*, i8** %10
%49 = call i32 @next_num(i8** %10, i8* %48)
%50 = load i8*, i8** %10
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %47
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
store i32 %54, i32* %8
br label %43
55: ; preds = %43
br label %56
56: ; preds = %55, %13
%57 = load i8*, i8** %10
%58 = icmp ne i8* %57, null
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i8*, i8** %10
%61 = call i32 @free(i8* %60)
br label %62
62: ; preds = %59, %56
%63 = load i32, i32* %6
ret i32 %63
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
br label %37
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
store i8* %11, i8** %3
%12 = icmp eq i32 %0, 2
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %21
15: ; preds = %9
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %11)
%20 = icmp sgt i32 %18, 0
br i1 %20, label %21, label %32
21: ; preds = %13, %15
%22 = phi i32 [ 10, %13 ], [ %18, %15 ]
br label %23
23: ; preds = %23, %21
%24 = phi i8* [ %11, %21 ], [ %31, %23 ]
%25 = phi i32 [ 0, %21 ], [ %29, %23 ]
%26 = call i32 @next_num(i8** %3, i8* %24)
%27 = load i8*, i8** %3
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = add nuw nsw i32 %25, 1
%30 = icmp eq i32 %29, %22
%31 = load i8*, i8** %3
br i1 %30, label %32, label %23
32: ; preds = %23, %15
%33 = phi i8* [ %11, %15 ], [ %31, %23 ]
%34 = icmp eq i8* %33, null
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = call i32 @free(i8* %33)
br label %37
37: ; preds = %6, %35, %32
%38 = phi i32 [ 1, %6 ], [ 0, %35 ], [ 0, %32 ]
ret i32 %38
}