#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*/ bgrtoyuv(unsigned char *, unsigned char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
unsigned char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ readtga(char *, unsigned char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ writeyuv(char *, unsigned char *);
int main(int argc, char **argv) {
  int fs, fe;
  int i;
  unsigned char *tgadata, *yuvdata;
  char tganame[800];
  char yuvname[800];
  int numnodes;
  int mynode;
  mynode = 0;
  numnodes = 1;
  tgadata = malloc(253440);
  yuvdata = malloc(168960);
  if (mynode == 0)
    printf("Converting 352x240 .tga files to abekas YUV files...\n");
  if (argc != 4) {
    if (mynode == 0)
      printf("Usage is: tgatoyuv basename  startframe#  endframe# \n");
    exit(0);
  }
  if (mynode == 0)
    printf("Using %s as base filename for frames %s -> %s\n", argv[1], argv[2],
           argv[3]);
  fs = atoi(argv[2]);
  fe = atoi(argv[3]);
  for (i = (fs + mynode); i <= fe; i += numnodes) {
    sprintf(tganame, "%s.%04d.tga", argv[1], i);
    sprintf(yuvname, "%s.%04d.yuv", argv[1], i);
    printf("converting %s -> %s . . .\n", tganame, yuvname);
    readtga(tganame, tgadata);
    bgrtoyuv(tgadata, yuvdata);
    writeyuv(yuvname, yuvdata);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x680,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x678(%rbp)
movl   $0x1,-0x674(%rbp)
mov    $0x3de00,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x29400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x678(%rbp)
jne    11e4 <main+0x64>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x4,-0x8(%rbp)
je     1210 <main+0x90>
cmpl   $0x0,-0x678(%rbp)
jne    1209 <main+0x89>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x678(%rbp)
jne    1243 <main+0xc3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rcx
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    -0x678(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     1311 <main+0x191>
lea    -0x350(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe07(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x670(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xdf5(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x350(%rbp),%rsi
lea    -0x670(%rbp),%rdx
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x350(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <readtga@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10a0 <bgrtoyuv@plt>
lea    -0x670(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <writeyuv@plt>
mov    -0x674(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    126f <main+0xef>
xor    %eax,%eax
add    $0x680,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x658,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x3de00,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x29400,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x4,%ebp
jne    12ac <main+0x11c>
mov    0x8(%rbx),%rsi
mov    0x10(%rbx),%rdx
mov    0x18(%rbx),%rcx
lea    0xe18(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    0x18(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,0xc(%rsp)
cmp    %eax,%ebp
jg     1298 <main+0x108>
addl   $0x1,0xc(%rsp)
lea    0x330(%rsp),%r13
lea    0x10(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rbx),%rdx
mov    %r13,%rdi
lea    0xdf1(%rip),%rsi
mov    %ebp,%ecx
call   1090 <sprintf@plt>
mov    0x8(%rbx),%rdx
mov    %r12,%rdi
lea    0xde8(%rip),%rsi
mov    %ebp,%ecx
call   1090 <sprintf@plt>
lea    0xde6(%rip),%rdi
mov    %r13,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1070 <readtga@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10b0 <bgrtoyuv@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <writeyuv@plt>
add    $0x1,%ebp
cmp    %ebp,0xc(%rsp)
jne    1230 <main+0xa0>
xor    %eax,%eax
add    $0x658,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde4(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [54 x i8] c"Converting 352x240 .tga files to abekas YUV files...\0A\00"
@.str.1 = [54 x i8] c"Usage is: tgatoyuv basename startframe# endframe# \0A\00"
@.str.2 = [47 x i8] c"Using %s as base filename for frames %s -> %s\0A\00"
@.str.3 = [12 x i8] c"%s.%04d.tga\00"
@.str.4 = [12 x i8] c"%s.%04d.yuv\00"
@.str.5 = [27 x i8] c"converting %s -> %s . . .\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 i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [800 x i8]
%12 = alloca [800 x i8]
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %14
store i32 1, i32* %13
%15 = call i8* @malloc(i32 253440)
store i8* %15, i8** %9
%16 = call i8* @malloc(i32 168960)
store i8* %16, i8** %10
%17 = load i32, i32* %14
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %2
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 4
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i32, i32* %14
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %24
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %21
%32 = load i32, i32* %14
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 3
%43 = load i8*, i8** %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %37, i8* %40, i8* %43)
br label %45
45: ; preds = %34, %31
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
%49 = call i32 @atoi(i8* %48)
store i32 %49, i32* %6
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 3
%52 = load i8*, i8** %51
%53 = call i32 @atoi(i8* %52)
store i32 %53, i32* %7
%54 = load i32, i32* %6
%55 = load i32, i32* %14
%56 = add nsw i32 %54, %55
store i32 %56, i32* %8
br label %57
57: ; preds = %86, %45
%58 = load i32, i32* %8
%59 = load i32, i32* %7
%60 = icmp sle i32 %58, %59
br i1 %60, label %61, label %90
61: ; preds = %57
%62 = getelementptr inbounds [800 x i8], [800 x i8]* %11, i64 0, i64 0
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 1
%65 = load i8*, i8** %64
%66 = load i32, i32* %8
%67 = call i32 @sprintf(i8* %62, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %65, i32 %66)
%68 = getelementptr inbounds [800 x i8], [800 x i8]* %12, i64 0, i64 0
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 1
%71 = load i8*, i8** %70
%72 = load i32, i32* %8
%73 = call i32 @sprintf(i8* %68, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %71, i32 %72)
%74 = getelementptr inbounds [800 x i8], [800 x i8]* %11, i64 0, i64 0
%75 = getelementptr inbounds [800 x i8], [800 x i8]* %12, i64 0, i64 0
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %74, i8* %75)
%77 = getelementptr inbounds [800 x i8], [800 x i8]* %11, i64 0, i64 0
%78 = load i8*, i8** %9
%79 = call i32 @readtga(i8* %77, i8* %78)
%80 = load i8*, i8** %9
%81 = load i8*, i8** %10
%82 = call i32 @bgrtoyuv(i8* %80, i8* %81)
%83 = getelementptr inbounds [800 x i8], [800 x i8]* %12, i64 0, i64 0
%84 = load i8*, i8** %10
%85 = call i32 @writeyuv(i8* %83, i8* %84)
br label %86
86: ; preds = %61
%87 = load i32, i32* %13
%88 = load i32, i32* %8
%89 = add nsw i32 %88, %87
store i32 %89, i32* %8
br label %57
90: ; preds = %57
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [47 x i8] c"Using %s as base filename for frames %s -> %s\0A\00"
@.str.3 = [12 x i8] c"%s.%04d.tga\00"
@.str.4 = [12 x i8] c"%s.%04d.yuv\00"
@.str.5 = [27 x i8] c"converting %s -> %s . . .\0A\00"
@str = [53 x i8] c"Converting 352x240 .tga files to abekas YUV files...\00"
@str.6 = [53 x i8] c"Usage is: tgatoyuv basename startframe# endframe# \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [800 x i8]
%4 = alloca [800 x i8]
%5 = getelementptr inbounds [800 x i8], [800 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [800 x i8], [800 x i8]* %4, i64 0, i64 0
%7 = tail call dereferenceable_or_null(253440) i8* @malloc(i32 253440)
%8 = tail call dereferenceable_or_null(168960) i8* @malloc(i32 168960)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
%10 = icmp eq i32 %0, 4
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.6, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %16, i8* %18, i8* %20)
%22 = load i8*, i8** %17
%23 = tail call i32 @atoi(i8* %22)
%24 = load i8*, i8** %19
%25 = tail call i32 @atoi(i8* %24)
%26 = icmp sgt i32 %23, %25
br i1 %26, label %39, label %27
27: ; preds = %14, %27
%28 = phi i32 [ %37, %27 ], [ %23, %14 ]
%29 = load i8*, i8** %15
%30 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %29, i32 %28)
%31 = load i8*, i8** %15
%32 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %31, i32 %28)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %5, i8* %6)
%34 = call i32 @readtga(i8* %5, i8* %7)
%35 = call i32 @bgrtoyuv(i8* %7, i8* %8)
%36 = call i32 @writeyuv(i8* %6, i8* %8)
%37 = add i32 %28, 1
%38 = icmp eq i32 %28, %25
br i1 %38, label %39, label %27
39: ; preds = %27, %14
ret i32 0
}