#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*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void *setUIO(int uio_index, int length) {
  char uio_buf[32];
  int uio_fd;
  void *uio_ptr;
  sprintf(uio_buf, "/dev/uio%d", uio_index);
  uio_fd = open(uio_buf, O_RDWR);
  if (uio_fd < 1) {
    printf("Invalid UIO device file: %s.\n", uio_buf);
  }
  uio_ptr = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, uio_fd, 0);
  return uio_ptr;
}


x86 assembly (clang, -O0):
<setUIO>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xea4(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x1,-0x34(%rbp)
jge    1190 <setUIO+0x50>
lea    -0x30(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
mov    0x2e25(%rip),%rax
or     (%rax),%edx
mov    0x2e3c(%rip),%rax
mov    (%rax),%ecx
mov    -0x34(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setUIO>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %edi,%edx
lea    0xeaf(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1060 <sprintf@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1050 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1182 <setUIO+0x42>
lea    0xe91(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
mov    0x2e6f(%rip),%rax
mov    0x2e38(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e4d(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebx,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/uio%d\00"
@O_RDWR = global i32 0
@.str.1 = [30 x i8] c"Invalid UIO device file: %s.\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
define i8* @setUIO(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [32 x i8]
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* %3
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%18 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %2
%20 = load i32, i32* %4
%21 = load i32, i32* @PROT_READ
%22 = load i32, i32* @PROT_WRITE
%23 = or i32 %21, %22
%24 = load i32, i32* @MAP_SHARED
%25 = load i32, i32* %6
%26 = call i8* @mmap(i32* null, i32 %20, i32 %23, i32 %24, i32 %25, i32 0)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
ret i8* %27
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/uio%d\00"
@O_RDWR = global i32 0
@.str.1 = [30 x i8] c"Invalid UIO device file: %s.\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
define i8* @setUIO(i32 %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* %4, i32 %6)
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %11
11: ; preds = %9, %2
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @PROT_WRITE
%14 = or i32 %13, %12
%15 = load i32, i32* @MAP_SHARED
%16 = call i8* @mmap(i32* null, i32 %1, i32 %14, i32 %15, i32 %7, i32 0)
ret i8* %16
}