#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_format {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ VIDIOC_S_FMT;
int /*<<< orphan*/ errno;
int xioctl(int, int /*<<< orphan*/, struct v4l2_format *);
int set_stream_format(int fd, struct v4l2_format *fmt) {
  if (fd < 0 || fmt == NULL) {
    errno = EINVAL;
    return -1;
  }
  return xioctl(fd, VIDIOC_S_FMT, fmt);
}


x86 assembly (clang, -O0):
<set_stream_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1134 <set_stream_format+0x24>
cmpq   $0x0,-0x10(%rbp)
jne    1152 <set_stream_format+0x42>
mov    0x2e95(%rip),%rax
mov    (%rax),%ecx
mov    0x2e94(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    116a <set_stream_format+0x5a>
mov    -0x8(%rbp),%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1030 <xioctl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_stream_format>:
test   %edi,%edi
js     112a <set_stream_format+0x1a>
mov    %rsi,%rdx
test   %rsi,%rsi
je     112a <set_stream_format+0x1a>
mov    0x2ebd(%rip),%rax
mov    (%rax),%esi
jmp    1030 <xioctl@plt>
mov    0x2e9f(%rip),%rax
mov    (%rax),%eax
mov    0x2e9e(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
%struct.v4l2_format = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
@VIDIOC_S_FMT = global i32 0
define i32 @set_stream_format(i32 %0, %struct.v4l2_format* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.v4l2_format*
store i32 %0, i32* %4
store %struct.v4l2_format* %1, %struct.v4l2_format** %5
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load %struct.v4l2_format*, %struct.v4l2_format** %5
%10 = icmp eq %struct.v4l2_format* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8, %2
%12 = load i32, i32* @EINVAL
store i32 %12, i32* @errno
store i32 -1, i32* %3
br label %18
13: ; preds = %8
%14 = load i32, i32* %4
%15 = load i32, i32* @VIDIOC_S_FMT
%16 = load %struct.v4l2_format*, %struct.v4l2_format** %5
%17 = call i32 @xioctl(i32 %14, i32 %15, %struct.v4l2_format* %16)
store i32 %17, i32* %3
br label %18
18: ; preds = %13, %11
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
%struct.v4l2_format = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
@VIDIOC_S_FMT = global i32 0
define i32 @set_stream_format(i32 %0, %struct.v4l2_format* %1) {
%3 = icmp slt i32 %0, 0
%4 = icmp eq %struct.v4l2_format* %1, null
%5 = or i1 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = load i32, i32* @EINVAL
store i32 %7, i32* @errno
br label %11
8: ; preds = %2
%9 = load i32, i32* @VIDIOC_S_FMT
%10 = tail call i32 @xioctl(i32 %0, i32 %9, %struct.v4l2_format* %1)
br label %11
11: ; preds = %8, %6
%12 = phi i32 [ -1, %6 ], [ %10, %8 ]
ret i32 %12
}