#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ print_capabilities(int);
int /*<<< orphan*/ print_format(int);
int /*<<< orphan*/ print_input_info(int);
int /*<<< orphan*/ set_input(int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void print_info(const char *device, int input_index) {
  int dev_fd = open(device, O_RDWR);
  if (dev_fd < 0) {
    fprintf(stderr, "Error: Couldn't open device (%s)\n", strerror(errno));
    return;
  };
  print_capabilities(dev_fd);
  print_input_info(dev_fd);
  set_input(dev_fd, input_index);
  print_format(dev_fd);
  close(dev_fd);
}


x86 assembly (clang, -O0):
<print_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11df <print_info+0x5f>
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe2b(%rip),%rsi
call   1060 <fprintf@plt>
jmp    120a <print_info+0x8a>
mov    -0x10(%rbp),%edi
call   1040 <print_capabilities@plt>
mov    -0x10(%rbp),%edi
call   1070 <print_input_info@plt>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <set_input@plt>
mov    -0x10(%rbp),%edi
call   1080 <print_format@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_info>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     11c4 <print_info+0x44>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <print_capabilities@plt>
mov    %ebp,%edi
call   1070 <print_input_info@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <set_input@plt>
mov    %ebp,%edi
call   1080 <print_format@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <close@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%ebx
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe1e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <fprintf@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"Error: Couldn't open device (%s)\0A\00"
@errno = global i32 0
define void @print_info(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %28
16: ; preds = %2
%17 = load i32, i32* %5
%18 = call i32 @print_capabilities(i32 %17)
%19 = load i32, i32* %5
%20 = call i32 @print_input_info(i32 %19)
%21 = load i32, i32* %5
%22 = load i32, i32* %4
%23 = call i32 @set_input(i32 %21, i32 %22)
%24 = load i32, i32* %5
%25 = call i32 @print_format(i32 %24)
%26 = load i32, i32* %5
%27 = call i32 @close(i32 %26)
br label %28
28: ; preds = %16, %11
ret void
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"Error: Couldn't open device (%s)\0A\00"
@errno = global i32 0
define void @print_info(i8* nocapture %0, i32 %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %17
11: ; preds = %2
%12 = tail call i32 @print_capabilities(i32 %4)
%13 = tail call i32 @print_input_info(i32 %4)
%14 = tail call i32 @set_input(i32 %4, i32 %1)
%15 = tail call i32 @print_format(i32 %4)
%16 = tail call i32 @close(i32 %4)
br label %17
17: ; preds = %11, %6
ret void
}