#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 */
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ *stderr;
int strlen(char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  int done;
  FILE *errlog;
  FILE *fcs;
  int index;
  char line[32 * 1024];
  int status;
  char *status_gets;
  status = 0;
  errlog = stderr;
  index = 1;
  done = 0;
  fcs = fopen(argv[1], "r");
  if (fcs == NULL) {
    status = -1;
    done = 1;
  };
  while (!done) {
    status_gets = fgets(line, sizeof(line), fcs);
    if (status_gets == NULL) {
      status = -2;
    };
    if (sizeof(line) == strlen(line)) {
      status = -3;
    };
    if (status != 0)
      done = 1;
    if (strlen(line) > 0) {
      char sample_name_base[1024];
      char sample_filename[1024];
      FILE *fjson;
      char command[1024];
      sprintf(sample_name_base, "%08d", index);
      sprintf(sample_filename, "%s.json", sample_name_base);
      fjson = fopen(sample_filename, "w");
      fprintf(fjson, "%s", line);
      fclose(fjson);
      sprintf(command, "cs-extract-cert %s", sample_name_base);
      system(command);
      if (0 == (index % 20000)) {
        sprintf(command, "x-snap %09d", index);
        system(command);
      };
      if (index > 1000000)
        done = 1;
    };
    if (!done)
      index++;
  };
  return (status);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8c50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x8034(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe42(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e3 <main+0x73>
movl   $0xffffffff,-0x8034(%rbp)
ff ff ff
movl   $0x1,-0x14(%rbp)
jmp    11e8 <main+0x78>
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11fe <main+0x8e>
jmp    1388 <main+0x218>
lea    -0x8030(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x8000,%esi
call   1060 <fgets@plt>
mov    %rax,-0x8040(%rbp)
cmpq   $0x0,-0x8040(%rbp)
jne    1232 <main+0xc2>
movl   $0xfffffffe,-0x8034(%rbp)
ff ff ff
lea    -0x8030(%rbp),%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
mov    $0x8000,%eax
cmp    %rcx,%rax
jne    1259 <main+0xe9>
movl   $0xfffffffd,-0x8034(%rbp)
ff ff ff
cmpl   $0x0,-0x8034(%rbp)
je     126d <main+0xfd>
movl   $0x1,-0x14(%rbp)
lea    -0x8030(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jle    1370 <main+0x200>
lea    -0x8440(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xd6f(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x8840(%rbp),%rdi
lea    -0x8440(%rbp),%rdx
lea    0xd58(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x8840(%rbp),%rdi
lea    0xd4b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8848(%rbp)
mov    -0x8848(%rbp),%rdi
lea    -0x8030(%rbp),%rdx
lea    0xd3c(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x8848(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x8c50(%rbp),%rdi
lea    -0x8440(%rbp),%rdx
lea    0xd06(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x8c50(%rbp),%rdi
call   1050 <system@plt>
mov    -0x2c(%rbp),%eax
mov    $0x4e20,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
cmp    %edx,%eax
jne    1357 <main+0x1e7>
lea    -0x8c50(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xce0(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x8c50(%rbp),%rdi
call   1050 <system@plt>
cmpl   $0xf4240,-0x2c(%rbp)
jle    136b <main+0x1fb>
movl   $0x1,-0x14(%rbp)
jmp    1370 <main+0x200>
cmpl   $0x0,-0x14(%rbp)
jne    1383 <main+0x213>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e8 <main+0x78>
mov    -0x8034(%rbp),%eax
add    $0x8c50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8c18,%rsp
mov    0x8(%rsi),%rdi
lea    0xe74(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     12d2 <main+0x162>
mov    $0x1,%ebp
lea    0xc10(%rsp),%r13
xor    %ebx,%ebx
jmp    11c7 <main+0x57>
cmp    $0xf4240,%ebp
ja     12d7 <main+0x167>
add    $0x1,%ebp
test   %ebx,%ebx
jne    12d7 <main+0x167>
mov    %r13,%rdi
mov    $0x8000,%esi
mov    0x8(%rsp),%rdx
call   1070 <fgets@plt>
test   %rax,%rax
mov    $0xfffffffe,%eax
cmove  %eax,%ebx
mov    %r13,%rdi
call   1040 <strlen@plt>
cmp    $0x8000,%eax
mov    $0xfffffffd,%eax
cmove  %eax,%ebx
mov    %r13,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11bc <main+0x4c>
mov    %ebp,%eax
mov    $0xd1b71759,%ecx
imul   %rcx,%rax
shr    $0x2e,%rax
imul   $0x4e20,%eax,%eax
mov    $0x1,%r15d
sub    %eax,%r15d
lea    0x810(%rsp),%r14
mov    %r14,%rdi
lea    0xdcd(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1090 <sprintf@plt>
lea    0x410(%rsp),%r12
mov    %r12,%rdi
lea    0xdb7(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %r12,%rdi
lea    0xdab(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
mov    %r13,%rdi
mov    %rax,%rsi
call   1060 <fputs@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
lea    0x10(%rsp),%r12
mov    %r12,%rdi
lea    0xd83(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %r12,%rdi
call   1050 <system@plt>
add    %ebp,%r15d
cmp    $0x1,%r15d
jne    11b0 <main+0x40>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
lea    0xd68(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %r14,%rdi
call   1050 <system@plt>
jmp    11b0 <main+0x40>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8c18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32* null
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"%08d\00"
@.str.2 = [8 x i8] c"%s.json\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [19 x i8] c"cs-extract-cert %s\00"
@.str.6 = [12 x i8] c"x-snap %09d\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 [32768 x i8]
%11 = alloca i32
%12 = alloca i8*
%13 = alloca [1024 x i8]
%14 = alloca [1024 x i8]
%15 = alloca i32*
%16 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
%17 = load i32*, i32** @stderr
store i32* %17, i32** %7
store i32 1, i32* %9
store i32 0, i32* %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %8
%22 = load i32*, i32** %8
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %2
store i32 -1, i32* %11
store i32 1, i32* %6
br label %25
25: ; preds = %24, %2
br label %26
26: ; preds = %90, %25
%27 = load i32, i32* %6
%28 = icmp ne i32 %27, 0
%29 = xor i1 %28, true
br i1 %29, label %30, label %91
30: ; preds = %26
%31 = getelementptr inbounds [32768 x i8], [32768 x i8]* %10, i64 0, i64 0
%32 = load i32*, i32** %8
%33 = call i8* @fgets(i8* %31, i32 32768, i32* %32)
store i8* %33, i8** %12
%34 = load i8*, i8** %12
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %37
36: ; preds = %30
store i32 -2, i32* %11
br label %37
37: ; preds = %36, %30
%38 = getelementptr inbounds [32768 x i8], [32768 x i8]* %10, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
%40 = sext i32 %39 to i64
%41 = icmp eq i64 32768, %40
br i1 %41, label %42, label %43
42: ; preds = %37
store i32 -3, i32* %11
br label %43
43: ; preds = %42, %37
%44 = load i32, i32* %11
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %43
store i32 1, i32* %6
br label %47
47: ; preds = %46, %43
%48 = getelementptr inbounds [32768 x i8], [32768 x i8]* %10, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %84
51: ; preds = %47
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%53 = load i32, i32* %9
%54 = call i32 (i8*, i8*, ...) @sprintf(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %53)
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%57 = call i32 (i8*, i8*, ...) @sprintf(i8* %55, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %56)
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%59 = call i32* @fopen(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %59, i32** %15
%60 = load i32*, i32** %15
%61 = getelementptr inbounds [32768 x i8], [32768 x i8]* %10, i64 0, i64 0
%62 = call i32 @fprintf(i32* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %61)
%63 = load i32*, i32** %15
%64 = call i32 @fclose(i32* %63)
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%67 = call i32 (i8*, i8*, ...) @sprintf(i8* %65, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %66)
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%69 = call i32 @system(i8* %68)
%70 = load i32, i32* %9
%71 = srem i32 %70, 20000
%72 = icmp eq i32 0, %71
br i1 %72, label %73, label %79
73: ; preds = %51
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%75 = load i32, i32* %9
%76 = call i32 (i8*, i8*, ...) @sprintf(i8* %74, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %75)
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%78 = call i32 @system(i8* %77)
br label %79
79: ; preds = %73, %51
%80 = load i32, i32* %9
%81 = icmp sgt i32 %80, 1000000
br i1 %81, label %82, label %83
82: ; preds = %79
store i32 1, i32* %6
br label %83
83: ; preds = %82, %79
br label %84
84: ; preds = %83, %47
%85 = load i32, i32* %6
%86 = icmp ne i32 %85, 0
br i1 %86, label %90, label %87
87: ; preds = %84
%88 = load i32, i32* %9
%89 = add nsw i32 %88, 1
store i32 %89, i32* %9
br label %90
90: ; preds = %87, %84
br label %26
91: ; preds = %26
%92 = load i32, i32* %11
ret i32 %92
}

LLVM IR (-O2):
@stderr = global i32* null
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"%08d\00"
@.str.2 = [8 x i8] c"%s.json\00"
@.str.3 = [2 x i8] c"w\00"
@.str.5 = [19 x i8] c"cs-extract-cert %s\00"
@.str.6 = [12 x i8] c"x-snap %09d\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [32768 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %46, label %12
12: ; preds = %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
br label %16
16: ; preds = %12, %43
%17 = phi i32 [ 1, %12 ], [ %45, %43 ]
%18 = phi i32 [ 0, %12 ], [ %24, %43 ]
%19 = call i8* @fgets(i8* %7, i32 32768, i32* %10)
%20 = icmp eq i8* %19, null
%21 = select i1 %20, i32 -2, i32 %18
%22 = call i32 @strlen(i8* %7)
%23 = icmp eq i32 %22, 32768
%24 = select i1 %23, i32 -3, i32 %21
%25 = icmp eq i32 %24, 0
%26 = call i32 @strlen(i8* %7)
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %43
28: ; preds = %16
%29 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%30 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%31 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @fputs(i8* %7, i32* %31)
%33 = call i32 @fclose(i32* %31)
%34 = call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %13)
%35 = call i32 @system(i8* %15)
%36 = urem i32 %17, 20000
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %28
%39 = call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %17)
%40 = call i32 @system(i8* %15)
br label %41
41: ; preds = %38, %28
%42 = icmp ugt i32 %17, 1000000
br i1 %42, label %46, label %43
43: ; preds = %41, %16
%44 = zext i1 %25 to i32
%45 = add nuw nsw i32 %17, %44
br i1 %25, label %16, label %46
46: ; preds = %41, %43, %2
%47 = phi i32 [ -1, %2 ], [ %24, %43 ], [ %24, %41 ]
ret i32 %47
}