#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*/ SEEK_SET;
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ write(int, char *, int);
int gpio_write(int fd, int val) {
  char c;
  int rc = -1;
  if (lseek(fd, 0, SEEK_SET) < 0)
    goto done;
  c = val ? '1' : '0';
  if (write(fd, &c, 1) < 0)
    goto done;
  rc = 0;
done:
  return rc;
}


x86 assembly (clang, -O0):
<gpio_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
cmp    $0x0,%rax
jge    1157 <gpio_write+0x37>
jmp    1194 <gpio_write+0x74>
mov    -0x8(%rbp),%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x9(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    118d <gpio_write+0x6d>
jmp    1194 <gpio_write+0x74>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_write>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2eb2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
test   %rax,%rax
js     115e <gpio_write+0x3e>
cmp    $0x1,%ebp
mov    $0x31,%al
sbb    $0x0,%al
mov    %al,0x7(%rsp)
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
sar    $0x3f,%rax
jmp    1163 <gpio_write+0x43>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @gpio_write(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 -1, i32* %6
%7 = load i32, i32* %3
%8 = load i32, i32* @SEEK_SET
%9 = call i64 @lseek(i32 %7, i32 0, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
br label %23
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
%15 = zext i1 %14 to i64
%16 = select i1 %14, i32 49, i32 48
%17 = trunc i32 %16 to i8
store i8 %17, i8* %5
%18 = load i32, i32* %3
%19 = call i64 @write(i32 %18, i8* %5, i32 1)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %12
br label %23
22: ; preds = %12
store i32 0, i32* %6
br label %23
23: ; preds = %22, %21, %11
%24 = load i32, i32* %6
ret i32 %24
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @gpio_write(i32 %0, i32 %1) {
%3 = alloca i8
%4 = load i32, i32* @SEEK_SET
%5 = tail call i64 @lseek(i32 %0, i32 0, i32 %4)
%6 = icmp slt i64 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = icmp eq i32 %1, 0
%9 = select i1 %8, i8 48, i8 49
store i8 %9, i8* %3
%10 = call i64 @write(i32 %0, i8* %3, i32 1)
%11 = ashr i64 %10, 63
%12 = trunc i64 %11 to i32
br label %13
13: ; preds = %7, %2
%14 = phi i32 [ -1, %2 ], [ %12, %7 ]
ret i32 %14
}