#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 v4l2_rect {
  scalar_t__ left;
  scalar_t__ top;
  scalar_t__ width;
  scalar_t__ height;
};

/* Variables and functions */
int /*<<< orphan*/ v4l2_rect_set_max_size(struct v4l2_rect *,
                                          struct v4l2_rect const *);
void v4l2_rect_map_inside(struct v4l2_rect *r,
                          const struct v4l2_rect *boundary) {
  v4l2_rect_set_max_size(r, boundary);
  if (r->left < boundary->left) {
    r->left = boundary->left;
  }
  if (r->top < boundary->top) {
    r->top = boundary->top;
  }
  if (r->left + r->width > boundary->width) {
    r->left = boundary->width - r->width;
  }
  if (r->top + r->height > boundary->height) {
    r->top = boundary->height - r->height;
  }
}


x86 assembly (clang, -O0):
<v4l2_rect_map_inside>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <v4l2_rect_set_max_size@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jge    114f <v4l2_rect_map_inside+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    0x8(%rcx),%rax
jge    1175 <v4l2_rect_map_inside+0x65>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
add    0x10(%rcx),%rax
mov    -0x10(%rbp),%rcx
cmp    0x10(%rcx),%rax
jle    11a9 <v4l2_rect_map_inside+0x99>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x8(%rbp),%rax
sub    0x10(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x8(%rbp),%rcx
add    0x18(%rcx),%rax
mov    -0x10(%rbp),%rcx
cmp    0x18(%rcx),%rax
jle    11df <v4l2_rect_map_inside+0xcf>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rcx
mov    -0x8(%rbp),%rax
sub    0x18(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v4l2_rect_map_inside>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <v4l2_rect_set_max_size@plt>
mov    (%rbx),%rcx
mov    (%r14),%rax
cmp    %rax,%rcx
jge    1130 <v4l2_rect_map_inside+0x20>
mov    %rax,(%rbx)
mov    %rax,%rcx
mov    0x8(%rbx),%rax
mov    0x8(%r14),%rdx
cmp    %rdx,%rax
jge    1144 <v4l2_rect_map_inside+0x34>
mov    %rdx,0x8(%rbx)
mov    %rdx,%rax
mov    0x10(%rbx),%rdx
add    %rdx,%rcx
mov    0x10(%r14),%rsi
cmp    %rsi,%rcx
jle    115a <v4l2_rect_map_inside+0x4a>
sub    %rdx,%rsi
mov    %rsi,(%rbx)
mov    0x18(%rbx),%rcx
add    %rcx,%rax
mov    0x18(%r14),%rdx
cmp    %rdx,%rax
jle    1171 <v4l2_rect_map_inside+0x61>
sub    %rcx,%rdx
mov    %rdx,0x8(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.v4l2_rect = type { i64, i64, i64, i64 }
define void @v4l2_rect_map_inside(%struct.v4l2_rect* %0, %struct.v4l2_rect* %1) {
%3 = alloca %struct.v4l2_rect*
%4 = alloca %struct.v4l2_rect*
store %struct.v4l2_rect* %0, %struct.v4l2_rect** %3
store %struct.v4l2_rect* %1, %struct.v4l2_rect** %4
%5 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%6 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%7 = call i32 @v4l2_rect_set_max_size(%struct.v4l2_rect* %5, %struct.v4l2_rect* %6)
%8 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%9 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %8, i32 0, i32 0
%10 = load i64, i64* %9
%11 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%12 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %11, i32 0, i32 0
%13 = load i64, i64* %12
%14 = icmp slt i64 %10, %13
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%17 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %16, i32 0, i32 0
%18 = load i64, i64* %17
%19 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%20 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %19, i32 0, i32 0
store i64 %18, i64* %20
br label %21
21: ; preds = %15, %2
%22 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%23 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %22, i32 0, i32 1
%24 = load i64, i64* %23
%25 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%26 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %25, i32 0, i32 1
%27 = load i64, i64* %26
%28 = icmp slt i64 %24, %27
br i1 %28, label %29, label %35
29: ; preds = %21
%30 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%31 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %30, i32 0, i32 1
%32 = load i64, i64* %31
%33 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%34 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %33, i32 0, i32 1
store i64 %32, i64* %34
br label %35
35: ; preds = %29, %21
%36 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%37 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %36, i32 0, i32 0
%38 = load i64, i64* %37
%39 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%40 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %39, i32 0, i32 2
%41 = load i64, i64* %40
%42 = add nsw i64 %38, %41
%43 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%44 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %43, i32 0, i32 2
%45 = load i64, i64* %44
%46 = icmp sgt i64 %42, %45
br i1 %46, label %47, label %57
47: ; preds = %35
%48 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%49 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %48, i32 0, i32 2
%50 = load i64, i64* %49
%51 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%52 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %51, i32 0, i32 2
%53 = load i64, i64* %52
%54 = sub nsw i64 %50, %53
%55 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%56 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %55, i32 0, i32 0
store i64 %54, i64* %56
br label %57
57: ; preds = %47, %35
%58 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%59 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %58, i32 0, i32 1
%60 = load i64, i64* %59
%61 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%62 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %61, i32 0, i32 3
%63 = load i64, i64* %62
%64 = add nsw i64 %60, %63
%65 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%66 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %65, i32 0, i32 3
%67 = load i64, i64* %66
%68 = icmp sgt i64 %64, %67
br i1 %68, label %69, label %79
69: ; preds = %57
%70 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%71 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %70, i32 0, i32 3
%72 = load i64, i64* %71
%73 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%74 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %73, i32 0, i32 3
%75 = load i64, i64* %74
%76 = sub nsw i64 %72, %75
%77 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%78 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %77, i32 0, i32 1
store i64 %76, i64* %78
br label %79
79: ; preds = %69, %57
ret void
}

LLVM IR (-O2):
%struct.v4l2_rect = type { i64, i64, i64, i64 }
define void @v4l2_rect_map_inside(%struct.v4l2_rect* %0, %struct.v4l2_rect* %1) {
%3 = tail call i32 @v4l2_rect_set_max_size(%struct.v4l2_rect* %0, %struct.v4l2_rect* %1)
%4 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %0, i64 0, i32 0
%5 = load i64, i64* %4
%6 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %1, i64 0, i32 0
%7 = load i64, i64* %6
%8 = icmp slt i64 %5, %7
br i1 %8, label %9, label %10
9: ; preds = %2
store i64 %7, i64* %4
br label %10
10: ; preds = %9, %2
%11 = phi i64 [ %7, %9 ], [ %5, %2 ]
%12 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %0, i64 0, i32 1
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %1, i64 0, i32 1
%15 = load i64, i64* %14
%16 = icmp slt i64 %13, %15
br i1 %16, label %17, label %18
17: ; preds = %10
store i64 %15, i64* %12
br label %18
18: ; preds = %17, %10
%19 = phi i64 [ %15, %17 ], [ %13, %10 ]
%20 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %0, i64 0, i32 2
%21 = load i64, i64* %20
%22 = add nsw i64 %21, %11
%23 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %1, i64 0, i32 2
%24 = load i64, i64* %23
%25 = icmp sgt i64 %22, %24
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = sub nsw i64 %24, %21
store i64 %27, i64* %4
br label %28
28: ; preds = %26, %18
%29 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %0, i64 0, i32 3
%30 = load i64, i64* %29
%31 = add nsw i64 %30, %19
%32 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %1, i64 0, i32 3
%33 = load i64, i64* %32
%34 = icmp sgt i64 %31, %33
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = sub nsw i64 %33, %30
store i64 %36, i64* %12
br label %37
37: ; preds = %35, %28
ret void
}