#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ get_line(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  int commit_after_n_rows;
  int this_row;
  char instring[1024];
  if (argc != 2) {
    fprintf(stderr, "usage: %s commit_after_n_rows\n", argv[0]);
    exit(1);
  }
  commit_after_n_rows = atoi(argv[1]);
  if (commit_after_n_rows <= 0) {
    fprintf(stderr, "%s: supply a positive number to commit after.\n", argv[0]);
    exit(1);
  }
  this_row = 0;
  while (get_line(instring, stdin)) {
    printf("%s\n", instring);
    if (++this_row == commit_after_n_rows) {
      this_row = 0;
      printf("commit;\n");
    }
  }
  printf("commit;\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1199 <main+0x49>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe76(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     11d9 <main+0x89>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe55(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     1240 <main+0xf0>
lea    -0x420(%rbp),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmp    -0x14(%rbp),%eax
jne    123b <main+0xeb>
movl   $0x0,-0x18(%rbp)
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e0 <main+0x90>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11fa <main+0xaa>
mov    0x8(%rbx),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    120f <main+0xbf>
mov    %eax,%r12d
mov    0x2e62(%rip),%r15
mov    (%r15),%esi
mov    %rsp,%rdi
call   1040 <get_line@plt>
test   %rax,%rax
je     11dc <main+0x8c>
xor    %ebp,%ebp
mov    %rsp,%rbx
lea    0xeac(%rip),%r14
jmp    11c0 <main+0x70>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <get_line@plt>
test   %rax,%rax
je     11dc <main+0x8c>
mov    %rbx,%rdi
call   1030 <puts@plt>
add    $0x1,%ebp
cmp    %r12d,%ebp
jne    11b0 <main+0x60>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
jmp    11b0 <main+0x60>
lea    0xe6b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdf3(%rip),%rsi
jmp    1222 <main+0xd2>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdfd(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"usage: %s commit_after_n_rows\0A\00"
@.str.1 = [47 x i8] c"%s: supply a positive number to commit after.\0A\00"
@stdin = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [9 x i8] c"commit;\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 [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %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* %6
%23 = load i32, i32* %6
%24 = icmp sle i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %18
store i32 0, i32* %7
br label %33
33: ; preds = %47, %32
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%35 = load i32, i32* @stdin
%36 = call i64 @get_line(i8* %34, i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %33
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
%43 = load i32, i32* %6
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %47
45: ; preds = %38
store i32 0, i32* %7
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45, %38
br label %33
48: ; preds = %33
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"usage: %s commit_after_n_rows\0A\00"
@.str.1 = [47 x i8] c"%s: supply a positive number to commit after.\0A\00"
@stdin = global i32 0
@str.4 = [8 x i8] c"commit;\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = icmp slt i32 %14, 1
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = load i32, i32* @stdin
%18 = call i64 @get_line(i8* %4, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %37, label %25
20: ; preds = %11
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %1
%23 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %16, %32
%26 = phi i32 [ %33, %32 ], [ 0, %16 ]
%27 = call i32 @puts(i8* %4)
%28 = add nsw i32 %26, 1
%29 = icmp eq i32 %28, %14
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.4, i64 0, i64 0))
br label %32
32: ; preds = %30, %25
%33 = phi i32 [ 0, %30 ], [ %28, %25 ]
%34 = load i32, i32* @stdin
%35 = call i64 @get_line(i8* %4, i32 %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %25
37: ; preds = %32, %16
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.4, i64 0, i64 0))
ret i32 0
}