#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 EXIT_SUCCESS;
int count_digits(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  int start = 0;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s limit [start=0]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if (argc == 3) {
    start = strtol(argv[2], NULL, 10);
  }
  {
    int i;
    char format[] = "%.0Xd\n";
    char digits[2];
    int limit = strtol(argv[1], NULL, 10);
    int width = count_digits(limit);
    sprintf(digits, "%d", width);
    format[3] = digits[0];
    for (i = start; i < limit; i++) {
      printf(format, i);
    }
  }
  return EXIT_SUCCESS;
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    11b1 <main+0x51>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe62(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jne    11d4 <main+0x74>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    0xe41(%rip),%eax
mov    %eax,-0x1f(%rbp)
mov    0xe3b(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xe33(%rip),%al
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1040 <count_digits@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x21(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xdff(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x21(%rbp),%al
mov    %al,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    125a <main+0xfa>
lea    -0x1f(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1234 <main+0xd4>
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
cmp    $0x1,%edi
jle    1203 <main+0xa3>
xor    %ebx,%ebx
cmp    $0x3,%edi
jne    118d <main+0x2d>
mov    0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%ebx
movl   $0xa6458,0xb(%rsp)
movl   $0x58302e25,0x8(%rsp)
58
mov    0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <count_digits@plt>
lea    0xe65(%rip),%rsi
lea    0x6(%rsp),%rdi
mov    %eax,%edx
call   1070 <sprintf@plt>
mov    0x6(%rsp),%al
mov    %al,0xb(%rsp)
cmp    %ebp,%ebx
jge    11f1 <main+0x91>
lea    0x8(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    11e0 <main+0x80>
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xde9(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s limit [start=0]\0A\00"
@EXIT_FAILURE = global i32 0
@__const.main.format = [7 x i8] c"%.0Xd\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [7 x i8]
%9 = alloca [2 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 3
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @strtol(i8* %28, i32* null, i32 10)
store i32 %29, i32* %6
br label %30
30: ; preds = %25, %22
%31 = bitcast [7 x i8]* %8 to i8*
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @strtol(i8* %34, i32* null, i32 10)
store i32 %35, i32* %10
%36 = load i32, i32* %10
%37 = call i32 @count_digits(i32 %36)
store i32 %37, i32* %11
%38 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%39 = load i32, i32* %11
%40 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%42 = load i8, i8* %41
%43 = getelementptr inbounds [7 x i8], [7 x i8]* %8, i64 0, i64 3
store i8 %42, i8* %43
%44 = load i32, i32* %6
store i32 %44, i32* %7
br label %45
45: ; preds = %53, %30
%46 = load i32, i32* %7
%47 = load i32, i32* %10
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %56
49: ; preds = %45
%50 = getelementptr inbounds [7 x i8], [7 x i8]* %8, i64 0, i64 0
%51 = load i32, i32* %7
%52 = call i32 @printf(i8* %50, i32 %51)
br label %53
53: ; preds = %49
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
br label %45
56: ; preds = %45
%57 = load i32, i32* @EXIT_SUCCESS
ret i32 %57
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s limit [start=0]\0A\00"
@EXIT_FAILURE = global i32 0
@__const.main.format = [7 x i8] c"%.0Xd\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [7 x i8]
%4 = alloca [2 x i8]
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = icmp eq i32 %0, 3
br i1 %13, label %14, label %18
14: ; preds = %12
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @strtol(i8* nocapture %16, i32* null, i32 10)
br label %18
18: ; preds = %14, %12
%19 = phi i32 [ %17, %14 ], [ 0, %12 ]
%20 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%21 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = tail call i32 @strtol(i8* nocapture %23, i32* null, i32 10)
%25 = tail call i32 @count_digits(i32 %24)
%26 = call i32 @sprintf(i8* %21, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i8, i8* %21
%28 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 3
store i8 %27, i8* %28
%29 = icmp slt i32 %19, %24
br i1 %29, label %30, label %35
30: ; preds = %18, %30
%31 = phi i32 [ %33, %30 ], [ %19, %18 ]
%32 = call i32 @printf(i8* %20, i32 %31)
%33 = add i32 %31, 1
%34 = icmp eq i32 %33, %24
br i1 %34, label %35, label %30
35: ; preds = %30, %18
%36 = load i32, i32* @EXIT_SUCCESS
ret i32 %36
}