#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->left + boundary->width)
    r->left = boundary->left + boundary->width - r->width;
  if (r->top + r->height > boundary->top + boundary->height)
    r->top = boundary->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
mov    (%rcx),%rcx
mov    -0x10(%rbp),%rdx
add    0x10(%rdx),%rcx
cmp    %rcx,%rax
jle    11ba <v4l2_rect_map_inside+0xaa>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
add    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
mov    0x8(%rcx),%rcx
mov    -0x10(%rbp),%rdx
add    0x18(%rdx),%rcx
cmp    %rcx,%rax
jle    1203 <v4l2_rect_map_inside+0xf3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
add    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,%rbx
mov    %rdi,%r14
call   1030 <v4l2_rect_set_max_size@plt>
mov    (%r14),%rcx
mov    (%rbx),%rax
cmp    %rax,%rcx
jge    1130 <v4l2_rect_map_inside+0x20>
mov    %rax,(%r14)
mov    %rax,%rcx
mov    0x8(%r14),%rax
mov    0x8(%rbx),%rdx
cmp    %rdx,%rax
jge    1144 <v4l2_rect_map_inside+0x34>
mov    %rdx,0x8(%r14)
mov    %rdx,%rax
mov    0x10(%r14),%rdx
add    %rdx,%rcx
mov    0x10(%rbx),%rsi
add    (%rbx),%rsi
cmp    %rsi,%rcx
jle    115d <v4l2_rect_map_inside+0x4d>
sub    %rdx,%rsi
mov    %rsi,(%r14)
mov    0x18(%r14),%rcx
add    %rcx,%rax
mov    0x18(%rbx),%rdx
add    0x8(%rbx),%rdx
cmp    %rdx,%rax
jle    1178 <v4l2_rect_map_inside+0x68>
sub    %rcx,%rdx
mov    %rdx,0x8(%r14)
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 0
%45 = load i64, i64* %44
%46 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%47 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %46, i32 0, i32 2
%48 = load i64, i64* %47
%49 = add nsw i64 %45, %48
%50 = icmp sgt i64 %42, %49
br i1 %50, label %51, label %65
51: ; preds = %35
%52 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%53 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %52, i32 0, i32 0
%54 = load i64, i64* %53
%55 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%56 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %55, i32 0, i32 2
%57 = load i64, i64* %56
%58 = add nsw i64 %54, %57
%59 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%60 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %59, i32 0, i32 2
%61 = load i64, i64* %60
%62 = sub nsw i64 %58, %61
%63 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%64 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %63, i32 0, i32 0
store i64 %62, i64* %64
br label %65
65: ; preds = %51, %35
%66 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%67 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %66, i32 0, i32 1
%68 = load i64, i64* %67
%69 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%70 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %69, i32 0, i32 3
%71 = load i64, i64* %70
%72 = add nsw i64 %68, %71
%73 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%74 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %73, i32 0, i32 1
%75 = load i64, i64* %74
%76 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%77 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %76, i32 0, i32 3
%78 = load i64, i64* %77
%79 = add nsw i64 %75, %78
%80 = icmp sgt i64 %72, %79
br i1 %80, label %81, label %95
81: ; preds = %65
%82 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%83 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %82, i32 0, i32 1
%84 = load i64, i64* %83
%85 = load %struct.v4l2_rect*, %struct.v4l2_rect** %4
%86 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %85, i32 0, i32 3
%87 = load i64, i64* %86
%88 = add nsw i64 %84, %87
%89 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%90 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %89, i32 0, i32 3
%91 = load i64, i64* %90
%92 = sub nsw i64 %88, %91
%93 = load %struct.v4l2_rect*, %struct.v4l2_rect** %3
%94 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %93, i32 0, i32 1
store i64 %92, i64* %94
br label %95
95: ; preds = %81, %65
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 = load i64, i64* %6
%24 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %1, i64 0, i32 2
%25 = load i64, i64* %24
%26 = add nsw i64 %25, %23
%27 = icmp sgt i64 %22, %26
br i1 %27, label %28, label %30
28: ; preds = %18
%29 = sub nsw i64 %26, %21
store i64 %29, i64* %4
br label %30
30: ; preds = %28, %18
%31 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %0, i64 0, i32 3
%32 = load i64, i64* %31
%33 = add nsw i64 %32, %19
%34 = load i64, i64* %14
%35 = getelementptr inbounds %struct.v4l2_rect, %struct.v4l2_rect* %1, i64 0, i32 3
%36 = load i64, i64* %35
%37 = add nsw i64 %36, %34
%38 = icmp sgt i64 %33, %37
br i1 %38, label %39, label %41
39: ; preds = %30
%40 = sub nsw i64 %37, %32
store i64 %40, i64* %12
br label %41
41: ; preds = %39, %30
ret void
}