#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) {
  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(3);
  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    -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    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11cb <load_iframe+0x5b>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1208 <load_iframe+0x98>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <read@plt>
mov    %eax,%esi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1070 <videoStillPicture@plt>
mov    $0x3,%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   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
mov    %rsp,%rsi
call   10a0 <fstat@plt>
mov    (%rsp),%ebx
mov    %ebx,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    %rax,0x8(%rsp)
mov    %ebx,0x10(%rsp)
lea    0xe4b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %rbp,%rbp
je     120a <load_iframe+0x8a>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1050 <read@plt>
lea    0xe3b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
call   1080 <videoStillPicture@plt>
mov    $0x3,%edi
call   1090 <sleep@plt>
mov    %r14d,%edi
call   1060 <videoPlay@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe11(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
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) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.stat
%6 = alloca %struct.video_still_picture
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = call i32 @fstat(i32 %7, %struct.stat* %5)
%9 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %6, i32 0, i32 0
store i8* %12, i8** %13
%14 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %6, i32 0, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %6, i32 0, i32 1
%18 = load i32, i32* %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %6, i32 0, i32 0
%21 = load i8*, i8** %20
%22 = icmp ne i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %38
25: ; preds = %2
%26 = load i32, i32* %3
%27 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %6, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %6, i32 0, i32 1
%30 = load i32, i32* %29
%31 = call i32 @read(i32 %26, i8* %28, i32 %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %4
%34 = call i32 @videoStillPicture(i32 %33, %struct.video_still_picture* %6)
%35 = call i32 @sleep(i32 3)
%36 = load i32, i32* %4
%37 = call i32 @videoPlay(i32 %36)
br label %38
38: ; preds = %25, %23
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) {
%3 = alloca %struct.stat
%4 = alloca %struct.video_still_picture
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast %struct.video_still_picture* %4 to i8*
%7 = call i32 @fstat(i32 %0, %struct.stat* %3)
%8 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %4, i64 0, i32 0
store i8* %11, i8** %12
%13 = getelementptr inbounds %struct.video_still_picture, %struct.video_still_picture* %4, i64 0, i32 1
store i32 %9, i32* %13
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %9)
%15 = icmp eq i64 %10, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %24
18: ; preds = %2
%19 = tail call i32 @read(i32 %0, i8* %11, i32 %9)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = call i32 @videoStillPicture(i32 %1, %struct.video_still_picture* %4)
%22 = call i32 @sleep(i32 3)
%23 = call i32 @videoPlay(i32 %1)
br label %24
24: ; preds = %18, %16
ret void
}