#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 GLint;
typedef scalar_t__ GLenum;

/* Variables and functions */
scalar_t__ GL_BITMAP;
int /*<<< orphan*/ assert(int);
int bytes_per_element(scalar_t__);
int elements_per_group(scalar_t__, scalar_t__);
GLint image_size(GLint width, GLint height, GLenum format, GLenum type) {
  int bytes_per_row;
  int components;
  assert(width > 0);
  assert(height > 0);
  components = elements_per_group(format, type);
  if (type == GL_BITMAP) {
    bytes_per_row = (width + 7) / 8;
  } else {
    bytes_per_row = bytes_per_element(type) * width;
  }
  return bytes_per_row * height * components;
}


x86 assembly (clang, -O0):
<image_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x0,-0x8(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <elements_per_group@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
jne    11a2 <image_size+0x72>
mov    -0x4(%rbp),%eax
add    $0x7,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
jmp    11b2 <image_size+0x82>
mov    -0x18(%rbp),%rdi
call   1030 <bytes_per_element@plt>
imul   -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x8(%rbp),%eax
imul   -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<image_size>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %esi,%r14d
mov    %edi,%ebx
xor    %edi,%edi
test   %ebx,%ebx
setg   %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %r14d,%r14d
setg   %dil
call   1040 <assert@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <elements_per_group@plt>
mov    %eax,%ebp
mov    0x2e77(%rip),%rax
cmp    %r15,(%rax)
jne    1186 <image_size+0x56>
lea    0x7(%rbx),%eax
add    $0xe,%ebx
test   %eax,%eax
cmovns %eax,%ebx
sar    $0x3,%ebx
jmp    1193 <image_size+0x63>
mov    %r15,%rdi
call   1030 <bytes_per_element@plt>
imul   %ebx,%eax
mov    %eax,%ebx
imul   %r14d,%ebp
imul   %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@GL_BITMAP = global i64 0
define i32 @image_size(i32 %0, i32 %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%11 = load i32, i32* %5
%12 = icmp sgt i32 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* %6
%16 = icmp sgt i32 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i64, i64* %7
%20 = load i64, i64* %8
%21 = call i32 @elements_per_group(i64 %19, i64 %20)
store i32 %21, i32* %10
%22 = load i64, i64* %8
%23 = load i64, i64* @GL_BITMAP
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %29
25: ; preds = %4
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 7
%28 = sdiv i32 %27, 8
store i32 %28, i32* %9
br label %34
29: ; preds = %4
%30 = load i64, i64* %8
%31 = call i32 @bytes_per_element(i64 %30)
%32 = load i32, i32* %5
%33 = mul nsw i32 %31, %32
store i32 %33, i32* %9
br label %34
34: ; preds = %29, %25
%35 = load i32, i32* %9
%36 = load i32, i32* %6
%37 = mul nsw i32 %35, %36
%38 = load i32, i32* %10
%39 = mul nsw i32 %37, %38
ret i32 %39
}

LLVM IR (-O2):
@GL_BITMAP = global i64 0
define i32 @image_size(i32 %0, i32 %1, i64 %2, i64 %3) {
%5 = icmp sgt i32 %0, 0
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp sgt i32 %1, 0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 @elements_per_group(i64 %2, i64 %3)
%12 = load i64, i64* @GL_BITMAP
%13 = icmp eq i64 %12, %3
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = add nsw i32 %0, 7
%16 = sdiv i32 %15, 8
br label %20
17: ; preds = %4
%18 = tail call i32 @bytes_per_element(i64 %3)
%19 = mul nsw i32 %18, %0
br label %20
20: ; preds = %17, %14
%21 = phi i32 [ %16, %14 ], [ %19, %17 ]
%22 = mul i32 %11, %1
%23 = mul i32 %22, %21
ret i32 %23
}