#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int tiwlan_signal(void) {
  char buf[256];
  int fd;
  int strength = -1;
  if ((fd = open("/proc/tiwlan", O_RDONLY)) >= 0) {
    read(fd, buf, sizeof(buf));
    strength = strtoul(buf, NULL, 0);
    close(fd);
  }
  return strength;
}


x86 assembly (clang, -O0):
<tiwlan_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0xffffffff,-0x108(%rbp)
ff ff ff
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x104(%rbp)
cmp    $0x0,%eax
jl     11b3 <tiwlan_signal+0x73>
mov    -0x104(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    $0x100,%edx
call   1040 <read@plt>
lea    -0x100(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x108(%rbp)
mov    -0x104(%rbp),%edi
call   1030 <close@plt>
mov    -0x108(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tiwlan_signal>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
lea    0xea7(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     118d <tiwlan_signal+0x4d>
mov    %eax,%ebx
mov    %rsp,%rbp
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x100,%edx
call   1040 <read@plt>
mov    %rbp,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
jmp    1192 <tiwlan_signal+0x52>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/tiwlan\00"
@O_RDONLY = global i32 0
define i32 @tiwlan_signal() {
%1 = alloca [256 x i8]
%2 = alloca i32
%3 = alloca i32
store i32 -1, i32* %3
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = icmp sge i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %0
%8 = load i32, i32* %2
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 256)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%12 = call i32 @strtoul(i8* %11, i32* null, i32 0)
store i32 %12, i32* %3
%13 = load i32, i32* %2
%14 = call i32 @close(i32 %13)
br label %15
15: ; preds = %7, %0
%16 = load i32, i32* %3
ret i32 %16
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/tiwlan\00"
@O_RDONLY = global i32 0
define i32 @tiwlan_signal() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp sgt i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = call i32 @read(i32 %4, i8* %2, i32 256)
%8 = call i32 @strtoul(i8* nocapture %2, i32* null, i32 0)
%9 = tail call i32 @close(i32 %4)
br label %10
10: ; preds = %6, %0
%11 = phi i32 [ %8, %6 ], [ -1, %0 ]
ret i32 %11
}