#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*/ atoi(char *);
scalar_t__ get_line(char *, int /*<<< orphan*/);
int /*<<< orphan*/ piece(char *, char, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ replace_field_with_new_value(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
void pad_leading_numbers(int fields_to_pad, int total_field_size) {
  char input_buffer[2048];
  char old_value[2048];
  char new_value[2048];
  int i;
  while (get_line(input_buffer, stdin)) {
    for (i = 0; i < fields_to_pad; i++) {
      if (!piece(old_value, '|', input_buffer, i)) {
        break;
      }
      sprintf(new_value, "%.*d", total_field_size, atoi(old_value));
      replace_field_with_new_value(input_buffer, new_value, i);
    }
    printf("%s\n", input_buffer);
  }
}


x86 assembly (clang, -O0):
<pad_leading_numbers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1820,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x810(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     1258 <pad_leading_numbers+0xf8>
movl   $0x0,-0x1814(%rbp)
mov    -0x1814(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1240 <pad_leading_numbers+0xe0>
lea    -0x1010(%rbp),%rdi
lea    -0x810(%rbp),%rdx
mov    -0x1814(%rbp),%ecx
mov    $0x7c,%esi
call   1080 <piece@plt>
cmp    $0x0,%eax
jne    11d5 <pad_leading_numbers+0x75>
jmp    1240 <pad_leading_numbers+0xe0>
lea    -0x1810(%rbp),%rax
mov    %rax,-0x1820(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1818(%rbp)
lea    -0x1010(%rbp),%rdi
call   1060 <atoi@plt>
mov    -0x1820(%rbp),%rdi
mov    -0x1818(%rbp),%edx
mov    %eax,%ecx
lea    0xdf2(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x810(%rbp),%rdi
lea    -0x1810(%rbp),%rsi
mov    -0x1814(%rbp),%edx
call   1050 <replace_field_with_new_value@plt>
mov    -0x1814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1814(%rbp)
jmp    119a <pad_leading_numbers+0x3a>
lea    -0x810(%rbp),%rsi
lea    0xdb7(%rip),%rdi
call   1040 <printf@plt>
jmp    1171 <pad_leading_numbers+0x11>
add    $0x1820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pad_leading_numbers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1808,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     122c <pad_leading_numbers+0xcc>
lea    0x1000(%rsp),%r13
mov    %rsp,%rbp
lea    0x800(%rsp),%rbx
jmp    11d5 <pad_leading_numbers+0x75>
cs nopw 0x0(%rax,%rax,1)
lea    0xe4e(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     122c <pad_leading_numbers+0xcc>
test   %r15d,%r15d
jle    11b0 <pad_leading_numbers+0x50>
xor    %r12d,%r12d
nopl   (%rax)
mov    %r13,%rdi
mov    $0x7c,%esi
mov    %rbp,%rdx
mov    %r12d,%ecx
call   1080 <piece@plt>
test   %eax,%eax
je     11b0 <pad_leading_numbers+0x50>
mov    %r13,%rdi
call   1060 <atoi@plt>
mov    %rbx,%rdi
lea    0xdf7(%rip),%rsi
mov    %r14d,%edx
mov    %eax,%ecx
call   1070 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1050 <replace_field_with_new_value@plt>
add    $0x1,%r12d
cmp    %r12d,%r15d
jne    11e0 <pad_leading_numbers+0x80>
jmp    11b0 <pad_leading_numbers+0x50>
add    $0x1808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [5 x i8] c"%.*d\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @pad_leading_numbers(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2048 x i8]
%6 = alloca [2048 x i8]
%7 = alloca [2048 x i8]
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
br label %9
9: ; preds = %39, %2
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i64 @get_line(i8* %10, i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %42
14: ; preds = %9
store i32 0, i32* %8
br label %15
15: ; preds = %36, %14
%16 = load i32, i32* %8
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %39
19: ; preds = %15
%20 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%21 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%22 = load i32, i32* %8
%23 = call i32 @piece(i8* %20, i8 signext 124, i8* %21, i32 %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %19
br label %39
26: ; preds = %19
%27 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%28 = load i32, i32* %4
%29 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%30 = call i32 @atoi(i8* %29)
%31 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %30)
%32 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%33 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%34 = load i32, i32* %8
%35 = call i32 @replace_field_with_new_value(i8* %32, i8* %33, i32 %34)
br label %36
36: ; preds = %26
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %15
39: ; preds = %25, %15
%40 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %40)
br label %9
42: ; preds = %9
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [5 x i8] c"%.*d\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @pad_leading_numbers(i32 %0, i32 %1) {
%3 = alloca [2048 x i8]
%4 = alloca [2048 x i8]
%5 = alloca [2048 x i8]
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i64 @get_line(i8* %6, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %30, label %12
12: ; preds = %2
%13 = icmp sgt i32 %0, 0
br label %14
14: ; preds = %12, %25
br i1 %13, label %15, label %25
15: ; preds = %14, %19
%16 = phi i32 [ %23, %19 ], [ 0, %14 ]
%17 = call i32 @piece(i8* %7, i8 signext 124, i8* %6, i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %15
%20 = call i32 @atoi(i8* %7)
%21 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %20)
%22 = call i32 @replace_field_with_new_value(i8* %6, i8* %8, i32 %16)
%23 = add nuw nsw i32 %16, 1
%24 = icmp eq i32 %23, %0
br i1 %24, label %25, label %15
25: ; preds = %19, %15, %14
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%27 = load i32, i32* @stdin
%28 = call i64 @get_line(i8* %6, i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %14
30: ; preds = %25, %2
ret void
}