#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 */

/* Variables and functions */
int lw6sys_imax(int, int /*<<< orphan*/);
int lw6sys_imin(int, int);
void check_bounds(int *x, int *y, int w, int h) {
  (*x) = lw6sys_imin((*x), w - 1);
  (*y) = lw6sys_imin((*y), h - 1);
  (*x) = lw6sys_imax((*x), 0);
  (*y) = lw6sys_imax((*y), 0);
}


x86 assembly (clang, -O0):
<check_bounds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
call   1030 <lw6sys_imin@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%esi
sub    $0x1,%esi
call   1030 <lw6sys_imin@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <lw6sys_imax@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <lw6sys_imax@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_bounds>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%edi
lea    -0x1(%rdx),%esi
call   1030 <lw6sys_imin@plt>
mov    %eax,(%rbx)
mov    (%r14),%edi
add    $0xffffffff,%ebp
mov    %ebp,%esi
call   1030 <lw6sys_imin@plt>
mov    %eax,(%r14)
mov    (%rbx),%edi
xor    %esi,%esi
call   1040 <lw6sys_imax@plt>
mov    %eax,(%rbx)
mov    (%r14),%edi
xor    %esi,%esi
call   1040 <lw6sys_imax@plt>
mov    %eax,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @check_bounds(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
%11 = load i32, i32* %7
%12 = sub nsw i32 %11, 1
%13 = call i32 @lw6sys_imin(i32 %10, i32 %12)
%14 = load i32*, i32** %5
store i32 %13, i32* %14
%15 = load i32*, i32** %6
%16 = load i32, i32* %15
%17 = load i32, i32* %8
%18 = sub nsw i32 %17, 1
%19 = call i32 @lw6sys_imin(i32 %16, i32 %18)
%20 = load i32*, i32** %6
store i32 %19, i32* %20
%21 = load i32*, i32** %5
%22 = load i32, i32* %21
%23 = call i32 @lw6sys_imax(i32 %22, i32 0)
%24 = load i32*, i32** %5
store i32 %23, i32* %24
%25 = load i32*, i32** %6
%26 = load i32, i32* %25
%27 = call i32 @lw6sys_imax(i32 %26, i32 0)
%28 = load i32*, i32** %6
store i32 %27, i32* %28
ret void
}

LLVM IR (-O2):
define void @check_bounds(i32* nocapture %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = load i32, i32* %0
%6 = add nsw i32 %2, -1
%7 = tail call i32 @lw6sys_imin(i32 %5, i32 %6)
store i32 %7, i32* %0
%8 = load i32, i32* %1
%9 = add nsw i32 %3, -1
%10 = tail call i32 @lw6sys_imin(i32 %8, i32 %9)
store i32 %10, i32* %1
%11 = load i32, i32* %0
%12 = tail call i32 @lw6sys_imax(i32 %11, i32 0)
store i32 %12, i32* %0
%13 = load i32, i32* %1
%14 = tail call i32 @lw6sys_imax(i32 %13, i32 0)
store i32 %14, i32* %1
ret void
}