#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_WRONLY;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ gpio_close_fd(int);
int gpio_get_fd(unsigned int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ write(int, char *, int);
void gpio_write_value(unsigned gpio, unsigned value) {
  int fd;
  if ((fd = gpio_get_fd(gpio, O_WRONLY)) != -1) {
    if (value) {
      write(fd, "1", 2);
    } else {
      write(fd, "0", 2);
    }
    gpio_close_fd(fd);
    return;
  }
  perror("failed to set value for pin");
  assert(0);
}


x86 assembly (clang, -O0):
<gpio_write_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
call   1030 <gpio_get_fd@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
je     11bf <gpio_write_value+0x6f>
cmpl   $0x0,-0x8(%rbp)
je     119e <gpio_write_value+0x4e>
mov    -0xc(%rbp),%edi
lea    0xe71(%rip),%rsi
mov    $0x2,%edx
call   1050 <write@plt>
jmp    11b2 <gpio_write_value+0x62>
mov    -0xc(%rbp),%edi
lea    0xe5a(%rip),%rsi
mov    $0x2,%edx
call   1050 <write@plt>
mov    -0xc(%rbp),%edi
call   1040 <gpio_close_fd@plt>
jmp    11d2 <gpio_write_value+0x82>
lea    0xe3e(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
call   1060 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_write_value>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
call   1030 <gpio_get_fd@plt>
cmp    $0xffffffff,%eax
je     1197 <gpio_write_value+0x47>
mov    %eax,%ebx
test   %ebp,%ebp
lea    0xe8f(%rip),%rax
lea    0xe86(%rip),%rsi
cmove  %rax,%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1050 <write@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <gpio_close_fd@plt>
lea    0xe66(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <assert@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [28 x i8] c"failed to set value for pin\00"
define void @gpio_write_value(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = load i32, i32* @O_WRONLY
%8 = call i32 @gpio_get_fd(i32 %6, i32 %7)
store i32 %8, i32* %5
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %22
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* %5
%15 = call i32 @write(i32 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 2)
br label %19
16: ; preds = %10
%17 = load i32, i32* %5
%18 = call i32 @write(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %19
19: ; preds = %16, %13
%20 = load i32, i32* %5
%21 = call i32 @gpio_close_fd(i32 %20)
br label %25
22: ; preds = %2
%23 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @assert(i32 0)
br label %25
25: ; preds = %22, %19
ret void
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [28 x i8] c"failed to set value for pin\00"
define void @gpio_write_value(i32 %0, i32 %1) {
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @gpio_get_fd(i32 %0, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = icmp eq i32 %1, 0
%8 = select i1 %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%9 = tail call i32 @write(i32 %4, i8* %8, i32 2)
%10 = tail call i32 @gpio_close_fd(i32 %4)
br label %14
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @assert(i32 0)
br label %14
14: ; preds = %11, %6
ret void
}