#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*/ EXIT_FAILURE;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_RDWR;
int O_SYNC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ gpio_base();
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int rpi_gpio_header_type();
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void set_rts_cts(int enable) {
  int gfpsel, gpiomask;
  int fd = open("/dev/mem", O_RDWR | O_SYNC);
  if (fd < 0) {
    fprintf(stderr, "can't open /dev/mem (%s)\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  void *gpio_map = mmap(NULL, (4 * 1024), PROT_READ | PROT_WRITE, MAP_SHARED,
                        fd, gpio_base());
  close(fd);
  if (gpio_map == MAP_FAILED) {
    fprintf(stderr, "mmap error (%s)\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  volatile unsigned *gpio = (volatile unsigned *)gpio_map;
  if (rpi_gpio_header_type() == 0x01) {
    gfpsel = (1);
    gpiomask = 0x00fc0000;
    enable ? printf("Enabling ") : printf("Disabling ");
    printf("CTS0 and RTS0 on GPIOs 16 and 17\n");
  } else {
    gfpsel = (3);
    gpiomask = 0x0000003f;
    enable ? printf("Enabling ") : printf("Disabling ");
    printf("CTS0 and RTS0 on GPIOs 30 and 31\n");
  }
  enable ? (gpio[gfpsel] |= gpiomask) : (gpio[gfpsel] &= ~gpiomask);
}


x86 assembly (clang, -O0):
<set_rts_cts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    0x2e25(%rip),%rax
or     (%rax),%esi
lea    0xe4c(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1200 <set_rts_cts+0x70>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe1c(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    0x2d98(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <gpio_base@plt>
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    %eax,%r9d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
call   1040 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%rax
mov    0x2d40(%rip),%rcx
cmp    (%rcx),%rax
jne    12a3 <set_rts_cts+0x113>
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xd93(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   10b0 <rpi_gpio_header_type@plt>
cmp    $0x1,%eax
jne    1301 <set_rts_cts+0x171>
movl   $0x1,-0x8(%rbp)
movl   $0xfc0000,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     12e4 <set_rts_cts+0x154>
lea    0xd5a(%rip),%rdi
call   1050 <printf@plt>
jmp    12f0 <set_rts_cts+0x160>
lea    0xd53(%rip),%rdi
call   1050 <printf@plt>
lea    0xd52(%rip),%rdi
call   1050 <printf@plt>
jmp    1342 <set_rts_cts+0x1b2>
movl   $0x3,-0x8(%rbp)
movl   $0x3f,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     132a <set_rts_cts+0x19a>
lea    0xd14(%rip),%rdi
call   1050 <printf@plt>
jmp    1336 <set_rts_cts+0x1a6>
lea    0xd0d(%rip),%rdi
call   1050 <printf@plt>
lea    0xd2e(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x0,-0x4(%rbp)
je     1364 <set_rts_cts+0x1d4>
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
or     %esi,%edx
mov    %edx,(%rax,%rcx,4)
jmp    137a <set_rts_cts+0x1ea>
mov    -0xc(%rbp),%esi
xor    $0xffffffff,%esi
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
and    %esi,%edx
mov    %edx,(%rax,%rcx,4)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_rts_cts>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
mov    0x2e26(%rip),%rax
mov    0x2e17(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe3c(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     129b <set_rts_cts+0xfb>
mov    %eax,%ebp
mov    0x2e1e(%rip),%rax
mov    0x2dc7(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2dfc(%rip),%rax
mov    (%rax),%r15d
xor    %eax,%eax
call   1040 <gpio_base@plt>
xor    %edi,%edi
mov    $0x1000,%esi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    %ebp,%r8d
mov    %eax,%r9d
call   1050 <mmap@plt>
mov    %rax,%r15
mov    %ebp,%edi
call   1070 <close@plt>
mov    0x2d82(%rip),%rax
cmp    (%rax),%r15
je     12bb <set_rts_cts+0x11b>
xor    %eax,%eax
call   10c0 <rpi_gpio_header_type@plt>
xor    %r12d,%r12d
cmp    $0x1,%eax
setne  %r12b
lea    0xe2b(%rip),%rax
lea    0xe03(%rip),%rbp
cmove  %rax,%rbp
mov    $0xfc0000,%eax
mov    $0x3f,%ebx
cmove  %eax,%ebx
test   %r14d,%r14d
lea    0xddd(%rip),%rax
lea    0xdcc(%rip),%rdi
cmove  %rax,%rdi
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
lea    (%r12,%r12,1),%rax
add    $0x1,%rax
test   %r14d,%r14d
je     128c <set_rts_cts+0xec>
or     %ebx,(%r15,%rax,4)
jmp    1292 <set_rts_cts+0xf2>
not    %ebx
and    %ebx,(%r15,%rax,4)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d1e(%rip),%rax
mov    (%rax),%ebx
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd50(%rip),%rsi
jmp    12d9 <set_rts_cts+0x139>
mov    0x2cfe(%rip),%rax
mov    (%rax),%ebx
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd4a(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"can't open /dev/mem (%s)\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [17 x i8] c"mmap error (%s)\0A\00"
@.str.3 = [10 x i8] c"Enabling \00"
@.str.4 = [11 x i8] c"Disabling \00"
@.str.5 = [34 x i8] c"CTS0 and RTS0 on GPIOs 16 and 17\0A\00"
@.str.6 = [34 x i8] c"CTS0 and RTS0 on GPIOs 30 and 31\0A\00"
define void @set_rts_cts(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
store i32 %0, i32* %2
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_SYNC
%10 = or i32 %8, %9
%11 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %1
%22 = load i32, i32* @PROT_READ
%23 = load i32, i32* @PROT_WRITE
%24 = or i32 %22, %23
%25 = load i32, i32* @MAP_SHARED
%26 = load i32, i32* %5
%27 = call i32 (...) @gpio_base()
%28 = call i8* @mmap(i32* null, i32 4096, i32 %24, i32 %25, i32 %26, i32 %27)
store i8* %28, i8** %6
%29 = load i32, i32* %5
%30 = call i32 @close(i32 %29)
%31 = load i8*, i8** %6
%32 = load i8*, i8** @MAP_FAILED
%33 = icmp eq i8* %31, %32
br i1 %33, label %34, label %41
34: ; preds = %21
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %21
%42 = load i8*, i8** %6
%43 = bitcast i8* %42 to i32*
store i32* %43, i32** %7
%44 = call i32 (...) @rpi_gpio_header_type()
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %56
46: ; preds = %41
store i32 1, i32* %3
store i32 16515072, i32* %4
%47 = load i32, i32* %2
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %53
51: ; preds = %46
%52 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %51, %49
%54 = phi i32 [ %50, %49 ], [ %52, %51 ]
%55 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
br label %66
56: ; preds = %41
store i32 3, i32* %3
store i32 63, i32* %4
%57 = load i32, i32* %2
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %63
61: ; preds = %56
%62 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %63
63: ; preds = %61, %59
%64 = phi i32 [ %60, %59 ], [ %62, %61 ]
%65 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
br label %66
66: ; preds = %63, %53
%67 = load i32, i32* %2
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %77
69: ; preds = %66
%70 = load i32, i32* %4
%71 = load i32*, i32** %7
%72 = load i32, i32* %3
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32, i32* %71, i64 %73
%75 = load volatile i32, i32* %74
%76 = or i32 %75, %70
store volatile i32 %76, i32* %74
br label %86
77: ; preds = %66
%78 = load i32, i32* %4
%79 = xor i32 %78, -1
%80 = load i32*, i32** %7
%81 = load i32, i32* %3
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i32, i32* %80, i64 %82
%84 = load volatile i32, i32* %83
%85 = and i32 %84, %79
store volatile i32 %85, i32* %83
br label %86
86: ; preds = %77, %69
%87 = phi i32 [ %76, %69 ], [ %85, %77 ]
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"can't open /dev/mem (%s)\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [17 x i8] c"mmap error (%s)\0A\00"
@.str.3 = [10 x i8] c"Enabling \00"
@.str.4 = [11 x i8] c"Disabling \00"
@str = [33 x i8] c"CTS0 and RTS0 on GPIOs 30 and 31\00"
@str.7 = [33 x i8] c"CTS0 and RTS0 on GPIOs 16 and 17\00"
define void @set_rts_cts(i32 %0) {
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_SYNC
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
%15 = load i32, i32* @PROT_READ
%16 = load i32, i32* @PROT_WRITE
%17 = or i32 %16, %15
%18 = load i32, i32* @MAP_SHARED
%19 = tail call i32 (...) @gpio_base()
%20 = tail call i8* @mmap(i32* null, i32 4096, i32 %17, i32 %18, i32 %5, i32 %19)
%21 = tail call i32 @close(i32 %5)
%22 = load i8*, i8** @MAP_FAILED
%23 = icmp eq i8* %20, %22
br i1 %23, label %24, label %31
24: ; preds = %14
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = tail call i8* @strerror(i32 %26)
%28 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %14
%32 = bitcast i8* %20 to i32*
%33 = tail call i32 (...) @rpi_gpio_header_type()
%34 = icmp eq i32 %33, 1
%35 = icmp eq i32 %0, 0
%36 = select i1 %34, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @str.7, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0)
%37 = select i1 %34, i32 16515072, i32 63
%38 = select i1 %34, i64 1, i64 3
%39 = select i1 %35, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0)
%40 = tail call i32 @printf(i8* dereferenceable(1) %39)
%41 = tail call i32 @puts(i8* dereferenceable(1) %36)
%42 = icmp eq i32 %0, 0
br i1 %42, label %47, label %43
43: ; preds = %31
%44 = getelementptr inbounds i32, i32* %32, i64 %38
%45 = load volatile i32, i32* %44
%46 = or i32 %45, %37
store volatile i32 %46, i32* %44
br label %52
47: ; preds = %31
%48 = xor i32 %37, -1
%49 = getelementptr inbounds i32, i32* %32, i64 %38
%50 = load volatile i32, i32* %49
%51 = and i32 %50, %48
store volatile i32 %51, i32* %49
br label %52
52: ; preds = %47, %43
ret void
}