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

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
int set_gpio_val_by_fd(int fd, uint8_t val) {
  int ret = 0;
  char buf[2] = {0};
  snprintf(buf, sizeof(buf), "%d", val);
  if (write(fd, buf, strlen(buf)) < 0)
    ret = 1;
  return ret;
}


x86 assembly (clang, -O0):
<set_gpio_val_by_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0xe(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1060 <memset@plt>
lea    -0xe(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x2,%esi
lea    0xe88(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0xe(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    -0xe(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11b3 <set_gpio_val_by_fd+0x73>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_gpio_val_by_fd>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ecx
mov    %edi,%ebp
movw   $0x0,0x6(%rsp)
lea    0xebb(%rip),%rdx
lea    0x6(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
shr    $0x3f,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @set_gpio_val_by_fd(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = bitcast [2 x i8]* %6 to i8*
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%9 = load i32, i32* %4
%10 = call i32 @snprintf(i8* %8, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %3
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = call i64 @write(i32 %11, i8* %12, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 1, i32* %5
br label %18
18: ; preds = %17, %2
%19 = load i32, i32* %5
ret i32 %19
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @set_gpio_val_by_fd(i32 %0, i32 %1) {
%3 = alloca i16
%4 = bitcast i16* %3 to i8*
store i16 0, i16* %3
%5 = call i32 @snprintf(i8* %4, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%6 = call i32 @strlen(i8* %4)
%7 = call i64 @write(i32 %0, i8* %4, i32 %6)
%8 = lshr i64 %7, 63
%9 = trunc i64 %8 to i32
ret i32 %9
}