#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 uint8_t;

/* Variables and functions */
int *malloc(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ memset(int *, int, int);
uint8_t *create_yuv420_frame(int windth, int height, int y, int u, int v) {
  int i;
  uint8_t *buf = NULL;
  uint8_t *cur_buf = NULL;
  uint8_t uv[2];
  if ((windth <= 0) || (height <= 0)) {
    return NULL;
  }
  buf = malloc(((100) * (100) * 3 / 2));
  memset(buf, y & 0xFF, (((100) * (100) * 3 / 2) * 2 / 3));
  cur_buf = buf + (((100) * (100) * 3 / 2) * 2 / 3);
  uv[0] = u & 0xFF;
  uv[1] = v & 0xFF;
  for (i = 0; i < (((100) * (100) * 3 / 2) / 3); i += 2) {
    memcpy(cur_buf, uv, 2);
    cur_buf += 2;
  }
  return buf;
}


x86 assembly (clang, -O0):
<create_yuv420_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    116c <create_yuv420_frame+0x3c>
cmpl   $0x0,-0x10(%rbp)
jg     1179 <create_yuv420_frame+0x49>
movq   $0x0,-0x8(%rbp)
jmp    120a <create_yuv420_frame+0xda>
mov    $0x3a98,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
and    $0xff,%esi
mov    $0x2710,%edx
call   1030 <memset@plt>
mov    -0x28(%rbp),%rax
add    $0x9c40,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x1388,-0x20(%rbp)
jge    1202 <create_yuv420_frame+0xd2>
mov    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    11c9 <create_yuv420_frame+0x99>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_yuv420_frame>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %r12d,%r12d
test   %edi,%edi
jle    11af <create_yuv420_frame+0x7f>
test   %esi,%esi
jle    11af <create_yuv420_frame+0x7f>
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %edx,%ebx
mov    $0x3a98,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
movzbl %bl,%esi
mov    %rax,%rdi
mov    $0x2710,%edx
call   1030 <memset@plt>
mov    %r12,%rbx
add    $0x9c40,%rbx
movzbl %r15b,%eax
mov    %eax,0x8(%rsp)
movzbl %r14b,%eax
mov    %eax,0xc(%rsp)
mov    $0xfffffffe,%ebp
lea    0x8(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
add    $0x8,%rbx
add    $0x2,%ebp
cmp    $0x1386,%ebp
jb     1190 <create_yuv420_frame+0x60>
mov    %r12,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @create_yuv420_frame(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca [2 x i32]
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32* null, i32** %13
store i32* null, i32** %14
%16 = load i32, i32* %7
%17 = icmp sle i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %5
%19 = load i32, i32* %8
%20 = icmp sle i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18, %5
store i32* null, i32** %6
br label %50
22: ; preds = %18
%23 = call i32* @malloc(i32 15000)
store i32* %23, i32** %13
%24 = load i32*, i32** %13
%25 = load i32, i32* %9
%26 = and i32 %25, 255
%27 = call i32 @memset(i32* %24, i32 %26, i32 10000)
%28 = load i32*, i32** %13
%29 = getelementptr inbounds i32, i32* %28, i64 10000
store i32* %29, i32** %14
%30 = load i32, i32* %10
%31 = and i32 %30, 255
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
store i32 %31, i32* %32
%33 = load i32, i32* %11
%34 = and i32 %33, 255
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 1
store i32 %34, i32* %35
store i32 0, i32* %12
br label %36
36: ; preds = %45, %22
%37 = load i32, i32* %12
%38 = icmp slt i32 %37, 5000
br i1 %38, label %39, label %48
39: ; preds = %36
%40 = load i32*, i32** %14
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
%42 = call i32 @memcpy(i32* %40, i32* %41, i32 2)
%43 = load i32*, i32** %14
%44 = getelementptr inbounds i32, i32* %43, i64 2
store i32* %44, i32** %14
br label %45
45: ; preds = %39
%46 = load i32, i32* %12
%47 = add nsw i32 %46, 2
store i32 %47, i32* %12
br label %36
48: ; preds = %36
%49 = load i32*, i32** %13
store i32* %49, i32** %6
br label %50
50: ; preds = %48, %21
%51 = load i32*, i32** %6
ret i32* %51
}

LLVM IR (-O2):
define i32* @create_yuv420_frame(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [2 x i32]
%7 = bitcast [2 x i32]* %6 to i8*
%8 = icmp slt i32 %0, 1
%9 = icmp slt i32 %1, 1
%10 = or i1 %8, %9
br i1 %10, label %27, label %11
11: ; preds = %5
%12 = tail call i32* @malloc(i32 15000)
%13 = and i32 %2, 255
%14 = tail call i32 @memset(i32* %12, i32 %13, i32 10000)
%15 = getelementptr inbounds i32, i32* %12, i64 10000
%16 = and i32 %3, 255
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
store i32 %16, i32* %17
%18 = and i32 %4, 255
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
store i32 %18, i32* %19
br label %20
20: ; preds = %11, %20
%21 = phi i32* [ %15, %11 ], [ %24, %20 ]
%22 = phi i32 [ 0, %11 ], [ %25, %20 ]
%23 = call i32 @memcpy(i32* %21, i32* %17, i32 2)
%24 = getelementptr inbounds i32, i32* %21, i64 2
%25 = add nuw nsw i32 %22, 2
%26 = icmp ult i32 %22, 4998
br i1 %26, label %20, label %27
27: ; preds = %20, %5
%28 = phi i32* [ null, %5 ], [ %12, %20 ]
ret i32* %28
}