#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 */
struct stat {
  size_t st_size;
};
struct gwavi_t {
  int dummy;
};
typedef scalar_t__ ssize_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(unsigned char *);
int fstat(int, struct stat *);
int gwavi_add_frame(struct gwavi_t *, unsigned char *, size_t);
int gwavi_close(struct gwavi_t *);
struct gwavi_t *gwavi_open(char *, unsigned int, unsigned int, char *,
                           unsigned int, int /*<<< orphan*/ *);
unsigned char *malloc(size_t);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ read(int, unsigned char *, size_t);
int sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int main(void) {
  struct gwavi_t *gwavi;
  unsigned int width = 320;
  unsigned int height = 240;
  unsigned int fps = 3;
  char *fourcc = "MJPG";
  char *avi_out = "example.avi";
  struct stat frame_stat;
  char filename[17];
  unsigned char *buffer;
  ssize_t r;
  size_t count, len, buffer_len = 0;
  int i, fd, ret;
  gwavi = gwavi_open(avi_out, width, height, fourcc, fps, NULL);
  if (!gwavi) {
    (void)fprintf(stderr, "Call to gwavi_open() failed!\n");
    return EXIT_FAILURE;
  }
  for (i = 1; i < 16; i++) {
    ret = sprintf(filename, "video-src/%02d.jpg", i);
    if (ret != 17 - 1) {
      if (ret < 0) {
        (void)fprintf(stderr, "An error occured during "
                              " snprintf call\n");
      } else {
        (void)fprintf(stderr, "Name of file to read was"
                              " truncated during sprintf call\n");
      }
      return EXIT_FAILURE;
    }
    fd = open(filename, O_RDONLY);
    if (fd == -1) {
      (void)fprintf(stderr, "Cannot open %s for reading\n", filename);
      perror(" ");
      return EXIT_FAILURE;
    }
    if (fstat(fd, &frame_stat) == -1) {
      (void)fprintf(stderr, "Could not stat frame\n");
      perror(" ");
      return EXIT_FAILURE;
    }
    len = frame_stat.st_size;
    if (len > buffer_len) {
      if (buffer_len > 0)
        free(buffer);
      buffer_len = len;
      buffer = malloc(buffer_len);
    }
    count = 0;
    while (count < len) {
      r = read(fd, buffer + count, len - count);
      if (r < 0) {
        (void)fprintf(stderr, "Failed to read from "
                              "buffer\n");
        perror(" ");
        return EXIT_FAILURE;
      }
      count += (size_t)r;
    }
    if (close(fd) == -1) {
      (void)fprintf(stderr, "Cannot close file descriptor\n");
      perror(" ");
      return EXIT_FAILURE;
    }
    if (gwavi_add_frame(gwavi, buffer, len) == -1) {
      (void)fprintf(stderr, "Cannot add frame to video\n");
      return EXIT_FAILURE;
    }
  }
  if (gwavi_close(gwavi) == -1) {
    (void)fprintf(stderr, "Call to gwavi_close() failed!\n");
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x140,-0x14(%rbp)
movl   $0xf0,-0x18(%rbp)
movl   $0x3,-0x1c(%rbp)
lea    0xe12(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe0c(%rip),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x78(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%r9d
call   10a0 <gwavi_open@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1258 <main+0x98>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1521 <main+0x361>
movl   $0x1,-0x7c(%rbp)
cmpl   $0x10,-0x7c(%rbp)
jge    14db <main+0x31b>
lea    -0x50(%rbp),%rdi
mov    -0x7c(%rbp),%edx
lea    0xdb8(%rip),%rsi
call   10d0 <sprintf@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x10,-0x84(%rbp)
je     12e0 <main+0x120>
cmpl   $0x0,-0x84(%rbp)
jge    12b8 <main+0xf8>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
lea    0xd96(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    12cf <main+0x10f>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1521 <main+0x361>
lea    -0x50(%rbp),%rdi
mov    0x2cfd(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x80(%rbp)
cmpl   $0xffffffff,-0x80(%rbp)
jne    1337 <main+0x177>
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rdx
lea    0xd8f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xd9d(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2ca3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1521 <main+0x361>
mov    -0x80(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   10e0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1380 <main+0x1c0>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
lea    0xd64(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xd54(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1521 <main+0x361>
mov    -0x38(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
cmp    -0x78(%rbp),%rax
jbe    13bf <main+0x1ff>
cmpq   $0x0,-0x78(%rbp)
jbe    13aa <main+0x1ea>
mov    -0x58(%rbp),%rdi
call   1040 <free@plt>
mov    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x58(%rbp)
movq   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%rax
cmp    -0x70(%rbp),%rax
jae    1441 <main+0x281>
mov    -0x80(%rbp),%edi
mov    -0x58(%rbp),%rsi
add    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rdx
sub    -0x68(%rbp),%rdx
call   1070 <read@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jge    1430 <main+0x270>
mov    0x2bd5(%rip),%rax
mov    (%rax),%edi
lea    0xcca(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xca4(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2baa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1521 <main+0x361>
mov    -0x60(%rbp),%rax
add    -0x68(%rbp),%rax
mov    %rax,-0x68(%rbp)
jmp    13c7 <main+0x207>
mov    -0x80(%rbp),%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    1486 <main+0x2c6>
mov    0x2b7f(%rip),%rax
mov    (%rax),%edi
lea    0xc90(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xc4e(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2b54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1521 <main+0x361>
mov    -0x10(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x70(%rbp),%rdx
call   1030 <gwavi_add_frame@plt>
cmp    $0xffffffff,%eax
jne    14c8 <main+0x308>
mov    0x2b31(%rip),%rax
mov    (%rax),%edi
lea    0xc60(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2b12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1521 <main+0x361>
jmp    14cd <main+0x30d>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    125f <main+0x9f>
mov    -0x10(%rbp),%rdi
call   1050 <gwavi_close@plt>
cmp    $0xffffffff,%eax
jne    1515 <main+0x355>
mov    0x2ae4(%rip),%rax
mov    (%rax),%edi
lea    0xc2e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2ac5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1521 <main+0x361>
mov    0x2aac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe30(%rip),%rdi
lea    0xe24(%rip),%rcx
mov    $0x140,%esi
mov    $0xf0,%edx
mov    $0x3,%r8d
xor    %r9d,%r9d
call   10a0 <gwavi_open@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1314 <main+0x154>
mov    $0x1,%ebp
xor    %r15d,%r15d
lea    0x20(%rsp),%r13
nop
mov    %r13,%rdi
lea    0xe15(%rip),%rsi
mov    %ebp,%edx
call   10d0 <sprintf@plt>
cmp    $0x10,%eax
jne    134b <main+0x18b>
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     13ab <main+0x1eb>
mov    %eax,%r12d
mov    %eax,%edi
lea    0x18(%rsp),%rsi
call   10e0 <fstat@plt>
cmp    $0xffffffff,%eax
je     13cc <main+0x20c>
mov    0x18(%rsp),%r14
cmp    %r15,%r14
jbe    1290 <main+0xd0>
test   %r15,%r15
je     1273 <main+0xb3>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%r15
jmp    1295 <main+0xd5>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %r14,%r14
je     12c7 <main+0x107>
mov    %r15,0x10(%rsp)
mov    %r13,%r15
xor    %r13d,%r13d
lea    (%rbx,%r13,1),%rsi
mov    %r14,%rdx
sub    %r13,%rdx
mov    %r12d,%edi
call   1070 <read@plt>
test   %rax,%rax
js     1326 <main+0x166>
add    %rax,%r13
cmp    %r13,%r14
ja     12a0 <main+0xe0>
mov    %r15,%r13
mov    0x10(%rsp),%r15
mov    %r12d,%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
je     13e1 <main+0x221>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <gwavi_add_frame@plt>
cmp    $0xffffffff,%eax
je     1361 <main+0x1a1>
add    $0x1,%ebp
cmp    $0x10,%ebp
jne    1210 <main+0x50>
mov    0x8(%rsp),%rdi
call   1050 <gwavi_close@plt>
cmp    $0xffffffff,%eax
je     137c <main+0x1bc>
mov    0x2cb9(%rip),%rax
jmp    139a <main+0x1da>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
lea    0xced(%rip),%rsi
jmp    138c <main+0x1cc>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xd7a(%rip),%rdi
call   10c0 <perror@plt>
jmp    1393 <main+0x1d3>
mov    0x2c86(%rip),%rcx
mov    (%rcx),%edi
test   %eax,%eax
js     1373 <main+0x1b3>
lea    0xd0b(%rip),%rsi
jmp    138c <main+0x1cc>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
lea    0xd9f(%rip),%rsi
jmp    138c <main+0x1cc>
lea    0xcc8(%rip),%rsi
jmp    138c <main+0x1cc>
mov    0x2c55(%rip),%rax
mov    (%rax),%edi
lea    0xd9f(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2c36(%rip),%rax
mov    (%rax),%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c26(%rip),%rax
mov    (%rax),%edi
lea    0xce7(%rip),%rsi
lea    0x20(%rsp),%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    133d <main+0x17d>
mov    0x2c05(%rip),%rax
mov    (%rax),%edi
lea    0xce4(%rip),%rsi
jmp    1336 <main+0x176>
mov    0x2bf0(%rip),%rax
mov    (%rax),%edi
lea    0xd01(%rip),%rsi
jmp    1336 <main+0x176>

LLVM IR (-O0):
%struct.gwavi_t = type { i32 }
%struct.stat = type { i64 }
@.str = [5 x i8] c"MJPG\00"
@.str.1 = [12 x i8] c"example.avi\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"Call to gwavi_open() failed!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [19 x i8] c"video-src/%02d.jpg\00"
@.str.4 = [40 x i8] c"An error occured during snprintf call\0A\00"
@.str.5 = [56 x i8] c"Name of file to read was truncated during sprintf call\0A\00"
@O_RDONLY = global i32 0
@.str.6 = [28 x i8] c"Cannot open %s for reading\0A\00"
@.str.7 = [2 x i8] c" \00"
@.str.8 = [22 x i8] c"Could not stat frame\0A\00"
@.str.9 = [28 x i8] c"Failed to read from buffer\0A\00"
@.str.10 = [30 x i8] c"Cannot close file descriptor\0A\00"
@.str.11 = [27 x i8] c"Cannot add frame to video\0A\00"
@.str.12 = [31 x i8] c"Call to gwavi_close() failed!\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.gwavi_t*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.stat
%9 = alloca [17 x i8]
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %1
store i32 320, i32* %3
store i32 240, i32* %4
store i32 3, i32* %5
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i64 0, i64* %14
%18 = load i8*, i8** %7
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = load i8*, i8** %6
%22 = load i32, i32* %5
%23 = call %struct.gwavi_t* @gwavi_open(i8* %18, i32 %19, i32 %20, i8* %21, i32 %22, i32* null)
store %struct.gwavi_t* %23, %struct.gwavi_t** %2
%24 = load %struct.gwavi_t*, %struct.gwavi_t** %2
%25 = icmp ne %struct.gwavi_t* %24, null
br i1 %25, label %30, label %26
26: ; preds = %0
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %1
br label %146
30: ; preds = %0
store i32 1, i32* %15
br label %31
31: ; preds = %133, %30
%32 = load i32, i32* %15
%33 = icmp slt i32 %32, 16
br i1 %33, label %34, label %136
34: ; preds = %31
%35 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 0
%36 = load i32, i32* %15
%37 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %36)
store i32 %37, i32* %17
%38 = load i32, i32* %17
%39 = icmp ne i32 %38, 16
br i1 %39, label %40, label %51
40: ; preds = %34
%41 = load i32, i32* %17
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %49
46: ; preds = %40
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0))
br label %49
49: ; preds = %46, %43
%50 = load i32, i32* @EXIT_FAILURE
store i32 %50, i32* %1
br label %146
51: ; preds = %34
%52 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 0
%53 = load i32, i32* @O_RDONLY
%54 = call i32 @open(i8* %52, i32 %53)
store i32 %54, i32* %16
%55 = load i32, i32* %16
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %63
57: ; preds = %51
%58 = load i32, i32* @stderr
%59 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 0
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %59)
%61 = call i32 @perror(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
store i32 %62, i32* %1
br label %146
63: ; preds = %51
%64 = load i32, i32* %16
%65 = call i32 @fstat(i32 %64, %struct.stat* %8)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %72
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%70 = call i32 @perror(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%71 = load i32, i32* @EXIT_FAILURE
store i32 %71, i32* %1
br label %146
72: ; preds = %63
%73 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%74 = load i64, i64* %73
store i64 %74, i64* %13
%75 = load i64, i64* %13
%76 = load i64, i64* %14
%77 = icmp ugt i64 %75, %76
br i1 %77, label %78, label %88
78: ; preds = %72
%79 = load i64, i64* %14
%80 = icmp ugt i64 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %78
%82 = load i8*, i8** %10
%83 = call i32 @free(i8* %82)
br label %84
84: ; preds = %81, %78
%85 = load i64, i64* %13
store i64 %85, i64* %14
%86 = load i64, i64* %14
%87 = call i8* @malloc(i64 %86)
store i8* %87, i8** %10
br label %88
88: ; preds = %84, %72
store i64 0, i64* %12
br label %89
89: ; preds = %109, %88
%90 = load i64, i64* %12
%91 = load i64, i64* %13
%92 = icmp ult i64 %90, %91
br i1 %92, label %93, label %113
93: ; preds = %89
%94 = load i32, i32* %16
%95 = load i8*, i8** %10
%96 = load i64, i64* %12
%97 = getelementptr inbounds i8, i8* %95, i64 %96
%98 = load i64, i64* %13
%99 = load i64, i64* %12
%100 = sub i64 %98, %99
%101 = call i64 @read(i32 %94, i8* %97, i64 %100)
store i64 %101, i64* %11
%102 = load i64, i64* %11
%103 = icmp slt i64 %102, 0
br i1 %103, label %104, label %109
104: ; preds = %93
%105 = load i32, i32* @stderr
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
%107 = call i32 @perror(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%108 = load i32, i32* @EXIT_FAILURE
store i32 %108, i32* %1
br label %146
109: ; preds = %93
%110 = load i64, i64* %11
%111 = load i64, i64* %12
%112 = add i64 %111, %110
store i64 %112, i64* %12
br label %89
113: ; preds = %89
%114 = load i32, i32* %16
%115 = call i32 @close(i32 %114)
%116 = icmp eq i32 %115, -1
br i1 %116, label %117, label %122
117: ; preds = %113
%118 = load i32, i32* @stderr
%119 = call i32 (i32, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0))
%120 = call i32 @perror(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%121 = load i32, i32* @EXIT_FAILURE
store i32 %121, i32* %1
br label %146
122: ; preds = %113
%123 = load %struct.gwavi_t*, %struct.gwavi_t** %2
%124 = load i8*, i8** %10
%125 = load i64, i64* %13
%126 = call i32 @gwavi_add_frame(%struct.gwavi_t* %123, i8* %124, i64 %125)
%127 = icmp eq i32 %126, -1
br i1 %127, label %128, label %132
128: ; preds = %122
%129 = load i32, i32* @stderr
%130 = call i32 (i32, i8*, ...) @fprintf(i32 %129, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%131 = load i32, i32* @EXIT_FAILURE
store i32 %131, i32* %1
br label %146
132: ; preds = %122
br label %133
133: ; preds = %132
%134 = load i32, i32* %15
%135 = add nsw i32 %134, 1
store i32 %135, i32* %15
br label %31
136: ; preds = %31
%137 = load %struct.gwavi_t*, %struct.gwavi_t** %2
%138 = call i32 @gwavi_close(%struct.gwavi_t* %137)
%139 = icmp eq i32 %138, -1
br i1 %139, label %140, label %144
140: ; preds = %136
%141 = load i32, i32* @stderr
%142 = call i32 (i32, i8*, ...) @fprintf(i32 %141, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0))
%143 = load i32, i32* @EXIT_FAILURE
store i32 %143, i32* %1
br label %146
144: ; preds = %136
%145 = load i32, i32* @EXIT_SUCCESS
store i32 %145, i32* %1
br label %146
146: ; preds = %144, %140, %128, %117, %104, %67, %57, %49, %26
%147 = load i32, i32* %1
ret i32 %147
}

LLVM IR (-O2):
%struct.stat = type { i64 }
%struct.gwavi_t = type { i32 }
@.str = [5 x i8] c"MJPG\00"
@.str.1 = [12 x i8] c"example.avi\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"Call to gwavi_open() failed!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [19 x i8] c"video-src/%02d.jpg\00"
@.str.4 = [40 x i8] c"An error occured during snprintf call\0A\00"
@.str.5 = [56 x i8] c"Name of file to read was truncated during sprintf call\0A\00"
@O_RDONLY = global i32 0
@.str.6 = [28 x i8] c"Cannot open %s for reading\0A\00"
@.str.7 = [2 x i8] c" \00"
@.str.8 = [22 x i8] c"Could not stat frame\0A\00"
@.str.9 = [28 x i8] c"Failed to read from buffer\0A\00"
@.str.10 = [30 x i8] c"Cannot close file descriptor\0A\00"
@.str.11 = [27 x i8] c"Cannot add frame to video\0A\00"
@.str.12 = [31 x i8] c"Call to gwavi_close() failed!\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.stat
%2 = alloca [17 x i8]
%3 = bitcast %struct.stat* %1 to i8*
%4 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%5 = tail call %struct.gwavi_t* @gwavi_open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 320, i32 240, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 3, i32* null)
%6 = icmp eq %struct.gwavi_t* %5, null
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
br label %15
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %91
12: ; preds = %79
%13 = add nuw nsw i32 %17, 1
%14 = icmp eq i32 %13, 16
br i1 %14, label %85, label %15
15: ; preds = %7, %12
%16 = phi i8* [ undef, %7 ], [ %71, %12 ]
%17 = phi i32 [ 1, %7 ], [ %13, %12 ]
%18 = phi i64 [ 0, %7 ], [ %72, %12 ]
%19 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%20 = icmp eq i32 %19, 16
br i1 %20, label %28, label %21
21: ; preds = %15
%22 = icmp slt i32 %19, 0
%23 = load i32, i32* @stderr
br i1 %22, label %24, label %26
24: ; preds = %21
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %91
26: ; preds = %21
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0))
br label %91
28: ; preds = %15
%29 = load i32, i32* @O_RDONLY
%30 = call i32 @open(i8* %4, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%35 = call i32 @perror(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %91
36: ; preds = %28
%37 = call i32 @fstat(i32 %30, %struct.stat* %1)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%42 = tail call i32 @perror(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %91
43: ; preds = %36
%44 = load i64, i64* %8
%45 = icmp ugt i64 %44, %18
br i1 %45, label %46, label %52
46: ; preds = %43
%47 = icmp eq i64 %18, 0
br i1 %47, label %50, label %48
48: ; preds = %46
%49 = tail call i32 @free(i8* %16)
br label %50
50: ; preds = %46, %48
%51 = tail call i8* @malloc(i64 %44)
br label %54
52: ; preds = %43
%53 = icmp eq i64 %44, 0
br i1 %53, label %70, label %54
54: ; preds = %50, %52
%55 = phi i8* [ %51, %50 ], [ %16, %52 ]
%56 = phi i64 [ %44, %50 ], [ %18, %52 ]
br label %59
57: ; preds = %59
%58 = icmp ugt i64 %44, %65
br i1 %58, label %59, label %70
59: ; preds = %54, %57
%60 = phi i64 [ %65, %57 ], [ 0, %54 ]
%61 = getelementptr inbounds i8, i8* %55, i64 %60
%62 = sub i64 %44, %60
%63 = tail call i64 @read(i32 %30, i8* %61, i64 %62)
%64 = icmp slt i64 %63, 0
%65 = add i64 %63, %60
br i1 %64, label %66, label %57
66: ; preds = %59
%67 = load i32, i32* @stderr
%68 = tail call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
%69 = tail call i32 @perror(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %91
70: ; preds = %57, %52
%71 = phi i8* [ %16, %52 ], [ %55, %57 ]
%72 = phi i64 [ %18, %52 ], [ %56, %57 ]
%73 = tail call i32 @close(i32 %30)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %79
75: ; preds = %70
%76 = load i32, i32* @stderr
%77 = tail call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0))
%78 = tail call i32 @perror(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %91
79: ; preds = %70
%80 = tail call i32 @gwavi_add_frame(%struct.gwavi_t* %5, i8* %71, i64 %44)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %12
82: ; preds = %79
%83 = load i32, i32* @stderr
%84 = tail call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
br label %91
85: ; preds = %12
%86 = tail call i32 @gwavi_close(%struct.gwavi_t* %5)
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %91
88: ; preds = %85
%89 = load i32, i32* @stderr
%90 = tail call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0))
br label %91
91: ; preds = %85, %24, %26, %88, %82, %75, %66, %39, %32, %9
%92 = phi i32* [ @EXIT_FAILURE, %32 ], [ @EXIT_FAILURE, %39 ], [ @EXIT_FAILURE, %66 ], [ @EXIT_FAILURE, %75 ], [ @EXIT_FAILURE, %82 ], [ @EXIT_FAILURE, %88 ], [ @EXIT_FAILURE, %9 ], [ @EXIT_FAILURE, %26 ], [ @EXIT_FAILURE, %24 ], [ @EXIT_SUCCESS, %85 ]
%93 = load i32, i32* %92
ret i32 %93
}