#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 video_still_picture {
  char *iFrame;
  int size;
};
struct stat {
  int st_size;
};

/* Variables and functions */
int /*<<< orphan*/ fstat(int, struct stat *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ videoPlay(int);
int /*<<< orphan*/ videoStillPicture(int, struct video_still_picture *);
void load_iframe(int filefd, int fd, int ti) {
  struct stat st;
  struct video_still_picture sp;
  fstat(filefd, &st);
  sp.iFrame = (char *)malloc(st.st_size);
  sp.size = st.st_size;
  printf("I-frame size: %d\n", sp.size);
  if (!sp.iFrame) {
    printf("No memory for I-Frame\n");
    return;
  }
  printf("read: %d bytes\n", read(filefd, sp.iFrame, sp.size));
  videoStillPicture(fd, &sp);
  sleep(ti);
  videoPlay(fd);
}


x86 assembly (clang, -O0):
<load_iframe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1090 <fstat@plt>
mov    -0x10(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11ce <load_iframe+0x5e>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1209 <load_iframe+0x99>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <read@plt>
mov    %eax,%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1070 <videoStillPicture@plt>
mov    -0xc(%rbp),%edi
call   1080 <sleep@plt>
mov    -0x8(%rbp),%edi
call   1050 <videoPlay@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_iframe>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%r12d
lea    0x8(%rsp),%rsi
call   10a0 <fstat@plt>
mov    0x8(%rsp),%ebx
mov    %ebx,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    %rax,0x10(%rsp)
mov    %ebx,0x18(%rsp)
lea    0xe43(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %rbp,%rbp
je     1212 <load_iframe+0x92>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1050 <read@plt>
lea    0xe33(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
call   1080 <videoStillPicture@plt>
mov    %r14d,%edi
call   1090 <sleep@plt>
mov    %r15d,%edi
call   1060 <videoPlay@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe09(%rip),%rdi
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.video_still_picture = type { i8*, i32 }
@.str = [18 x i8] c"I-frame size: %d\0A\00"
@.str.1 = [23 x i8] c"No memory for I-Frame\0A\00"
@.str.2 = [16 x i8] c"read: %d bytes\0A\00"
define void @load_iframe(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca %struct.video_still_picture
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
%10 = call i32 @fstat(i32 %9, %struct.stat* %7)
%11 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
%15 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %8, i32 0, i32 0
store i8* %14, i8** %15
%16 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %8, i32 0, i32 1
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %8, i32 0, i32 1
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %8, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = icmp ne i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %3
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %41
27: ; preds = %3
%28 = load i32, i32* %4
%29 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %8, i32 0, i32 0
%30 = load i8*, i8** %29
%31 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %8, i32 0, i32 1
%32 = load i32, i32* %31
%33 = call i32 @read(i32 %28, i8* %30, i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %5
%36 = call i32 @videoStillPicture(i32 %35, %struct.video_still_picture* %8)
%37 = load i32, i32* %6
%38 = call i32 @sleep(i32 %37)
%39 = load i32, i32* %5
%40 = call i32 @videoPlay(i32 %39)
br label %41
41: ; preds = %27, %25
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.video_still_picture = type { i8*, i32 }
@.str = [18 x i8] c"I-frame size: %d\0A\00"
@.str.2 = [16 x i8] c"read: %d bytes\0A\00"
@str = [22 x i8] c"No memory for I-Frame\00"
define void @load_iframe(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.stat
%5 = alloca %struct.video_still_picture
%6 = bitcast %struct.stat* %4 to i8*
%7 = bitcast %struct.video_still_picture* %5 to i8*
%8 = call i32 @fstat(i32 %0, %struct.stat* %4)
%9 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %5, i64 0, i32 0
store i8* %12, i8** %13
%14 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %5, i64 0, i32 1
store i32 %10, i32* %14
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %10)
%16 = icmp eq i64 %11, 0
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %25
19: ; preds = %3
%20 = tail call i32 @read(i32 %0, i8* %12, i32 %10)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = call i32 @videoStillPicture(i32 %1, %struct.video_still_picture* %5)
%23 = call i32 @sleep(i32 %2)
%24 = call i32 @videoPlay(i32 %1)
br label %25
25: ; preds = %19, %17
ret void
}