#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*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ output_pgm(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ process_gocr_output(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stderr;
int system(char *);
int /*<<< orphan*/ unlink(char *);
void run_ocr(int region, unsigned long long pts) {
  FILE *f;
  char inbuf[128];
  char outbuf[128];
  char cmd[512];
  int cmdres;
  sprintf(inbuf, "subtitle-%llu-%d.pgm", pts / 90, region);
  sprintf(outbuf, "tmp.txt");
  f = fopen(inbuf, "w");
  output_pgm(f, region);
  fclose(f);
  sprintf(cmd,
          "gocr"
          " -s 8 -d 0 -m 130  -i %s -o %s",
          inbuf, outbuf);
  cmdres = system(cmd);
  if (cmdres < 0) {
    perror("system failed");
    exit(EXIT_FAILURE);
  } else if (cmdres) {
    fprintf(stderr,
            "gocr"
            " returned %d\n",
            cmdres);
    exit(cmdres);
  }
  process_gocr_output(outbuf, region);
  unlink(inbuf);
  unlink(outbuf);
}


x86 assembly (clang, -O0):
<run_ocr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x330,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    $0x5a,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
mov    -0x4(%rbp),%ecx
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   10c0 <output_pgm@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x320(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    -0x120(%rbp),%rcx
lea    0xde7(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    -0x320(%rbp),%rdi
call   1060 <system@plt>
mov    %eax,-0x324(%rbp)
cmpl   $0x0,-0x324(%rbp)
jge    1278 <run_ocr+0xd8>
lea    0xddd(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
cmpl   $0x0,-0x324(%rbp)
je     12ab <run_ocr+0x10b>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
mov    -0x324(%rbp),%edx
lea    0xdb5(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x324(%rbp),%edi
call   10b0 <exit@plt>
jmp    12b0 <run_ocr+0x110>
lea    -0x120(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1040 <process_gocr_output@plt>
lea    -0xa0(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x120(%rbp),%rdi
call   1030 <unlink@plt>
add    $0x330,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_ocr>:
push   %rbp
push   %r14
push   %rbx
sub    $0x300,%rsp
mov    %rsi,%rax
mov    %edi,%ebx
movabs $0x2d82d82d82d82d83,%rcx
d8 82 2d
mul    %rcx
shr    $0x4,%rdx
lea    0xe38(%rip),%rsi
lea    0x80(%rsp),%r14
mov    %r14,%rdi
mov    %ebx,%ecx
xor    %eax,%eax
call   10a0 <sprintf@plt>
movabs $0x7478742e706d74,%rax
mov    %rax,(%rsp)
lea    0xe24(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %ebx,%esi
call   10c0 <output_pgm@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
lea    0xe02(%rip),%rsi
lea    0x100(%rsp),%rbp
mov    %rsp,%rcx
mov    %rbp,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %rbp,%rdi
call   1060 <system@plt>
test   %eax,%eax
js     1269 <run_ocr+0xc9>
jne    1283 <run_ocr+0xe3>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %ebx,%esi
call   1040 <process_gocr_output@plt>
lea    0x80(%rsp),%rdi
call   1030 <unlink@plt>
mov    %rbp,%rdi
call   1030 <unlink@plt>
add    $0x300,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdca(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    %eax,%ebp
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
lea    0xdb3(%rip),%rsi
mov    %ebp,%edx
call   1070 <fprintf@plt>
mov    %ebp,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"subtitle-%llu-%d.pgm\00"
@.str.1 = [8 x i8] c"tmp.txt\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [35 x i8] c"gocr -s 8 -d 0 -m 130 -i %s -o %s\00"
@.str.4 = [14 x i8] c"system failed\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.5 = [18 x i8] c"gocr returned %d\0A\00"
define void @run_ocr(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32*
%6 = alloca [128 x i8]
%7 = alloca [128 x i8]
%8 = alloca [512 x i8]
%9 = alloca i32
store i32 %0, i32* %3
store i64 %1, i64* %4
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%11 = load i64, i64* %4
%12 = udiv i64 %11, 90
%13 = load i32, i32* %3
%14 = call i32 (i8*, i8*, ...) @sprintf(i8* %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %12, i32 %13)
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %5
%19 = load i32*, i32** %5
%20 = load i32, i32* %3
%21 = call i32 @output_pgm(i32* %19, i32 %20)
%22 = load i32*, i32** %5
%23 = call i32 @fclose(i32* %22)
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%27 = call i32 (i8*, i8*, ...) @sprintf(i8* %24, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %25, i8* %26)
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%29 = call i32 @system(i8* %28)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %2
%33 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %2
%37 = load i32, i32* %9
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = load i32, i32* %9
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %9
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %36
br label %46
46: ; preds = %45
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%48 = load i32, i32* %3
%49 = call i32 @process_gocr_output(i8* %47, i32 %48)
%50 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%51 = call i32 @unlink(i8* %50)
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%53 = call i32 @unlink(i8* %52)
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"subtitle-%llu-%d.pgm\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [35 x i8] c"gocr -s 8 -d 0 -m 130 -i %s -o %s\00"
@.str.4 = [14 x i8] c"system failed\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.5 = [18 x i8] c"gocr returned %d\0A\00"
define void @run_ocr(i32 %0, i64 %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = alloca [512 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%9 = udiv i64 %1, 90
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %9, i32 %0)
%11 = bitcast [128 x i8]* %4 to i64*
store i64 32783537689095540, i64* %11
%12 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @output_pgm(i32* %12, i32 %0)
%14 = tail call i32 @fclose(i32* %12)
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %6, i8* %7)
%16 = call i32 @system(i8* %8)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = icmp eq i32 %16, 0
br i1 %23, label %28, label %24
24: ; preds = %22
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%27 = call i32 @exit(i32 %16)
unreachable
28: ; preds = %22
%29 = call i32 @process_gocr_output(i8* %7, i32 %0)
%30 = call i32 @unlink(i8* %6)
%31 = call i32 @unlink(i8* %7)
ret void
}