#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 EOF;
int atoi(char *);
int getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(int);
int main(int argc, char *argv[]) {
  int ch, to_pad, line = 0;
  if (argc != 2)
    goto exit_error;
  to_pad = atoi(argv[1]);
  while ((ch = getchar()) != EOF) {
    if (ch == ('\n'))
      ++line;
    putchar(ch);
  }
  if (line >= to_pad)
    return 0;
  to_pad -= line;
  while (to_pad--)
    printf("0x0\n");
  return 0;
exit_error:
  printf("Usage:\n\t./padhex nlines < in.hex > out.hex");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     116c <main+0x2c>
jmp    1209 <main+0xc9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%eax
je     11b5 <main+0x75>
cmpl   $0xa,-0x14(%rbp)
jne    11a8 <main+0x68>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <putchar@plt>
jmp    117c <main+0x3c>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     11cd <main+0x8d>
movl   $0x0,-0x4(%rbp)
jmp    121c <main+0xdc>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     11fd <main+0xbd>
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
jmp    11d8 <main+0x98>
movl   $0x0,-0x4(%rbp)
jmp    121c <main+0xdc>
lea    0xdf5(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11ce <main+0x7e>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%r15d
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e6f(%rip),%rbp
mov    $0x0,%ebx
cmp    0x0(%rbp),%eax
je     11ad <main+0x5d>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebx
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    0x0(%rbp),%eax
jne    1190 <main+0x40>
mov    %r15d,%eax
sub    %ebx,%eax
jle    11e0 <main+0x90>
je     11e0 <main+0x90>
sub    %r15d,%ebx
lea    0xe6b(%rip),%rbp
mov    %rbp,%rdi
call   1040 <puts@plt>
inc    %ebx
jne    11c0 <main+0x70>
jmp    11e0 <main+0x90>
lea    0xe2b(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [5 x i8] c"0x0\0A\00"
@.str.1 = [43 x i8] c"Usage:\0A\09./padhex nlines < in.hex > out.hex\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
br label %46
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %7
br label %17
17: ; preds = %27, %12
%18 = call i32 (...) @getchar()
store i32 %18, i32* %6
%19 = load i32, i32* @EOF
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %30
21: ; preds = %17
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
br label %27
27: ; preds = %24, %21
%28 = load i32, i32* %6
%29 = call i32 @putchar(i32 %28)
br label %17
30: ; preds = %17
%31 = load i32, i32* %8
%32 = load i32, i32* %7
%33 = icmp sge i32 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 0, i32* %3
br label %48
35: ; preds = %30
%36 = load i32, i32* %8
%37 = load i32, i32* %7
%38 = sub nsw i32 %37, %36
store i32 %38, i32* %7
br label %39
39: ; preds = %43, %35
%40 = load i32, i32* %7
%41 = add nsw i32 %40, -1
store i32 %41, i32* %7
%42 = icmp ne i32 %40, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %39
45: ; preds = %39
store i32 0, i32* %3
br label %48
46: ; preds = %11
%47 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %48
48: ; preds = %46, %45, %34
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.1 = [43 x i8] c"Usage:\0A\09./padhex nlines < in.hex > out.hex\00"
@str = [4 x i8] c"0x0\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %32
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = tail call i32 (...) @getchar()
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %21, label %11
11: ; preds = %4, %11
%12 = phi i32 [ %18, %11 ], [ %8, %4 ]
%13 = phi i32 [ %16, %11 ], [ 0, %4 ]
%14 = icmp eq i32 %12, 10
%15 = zext i1 %14 to i32
%16 = add nuw nsw i32 %13, %15
%17 = tail call i32 @putchar(i32 %12)
%18 = tail call i32 (...) @getchar()
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %11
21: ; preds = %11, %4
%22 = phi i32 [ 0, %4 ], [ %16, %11 ]
%23 = icmp sle i32 %7, %22
%24 = sub nsw i32 %7, %22
%25 = icmp eq i32 %24, 0
%26 = select i1 %23, i1 true, i1 %25
br i1 %26, label %34, label %27
27: ; preds = %21, %27
%28 = phi i32 [ %29, %27 ], [ %24, %21 ]
%29 = add nsw i32 %28, -1
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%31 = icmp eq i32 %29, 0
br i1 %31, label %34, label %27
32: ; preds = %2
%33 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %27, %21, %32
%35 = phi i32 [ 1, %32 ], [ 0, %21 ], [ 0, %27 ]
ret i32 %35
}