#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*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void set_gpio(int gpio, int value) {
  char buf[255];
  sprintf(buf, "/sys/class/gpio/gpio%d/value", gpio);
  int fd = open(buf, O_WRONLY);
  sprintf(buf, "%d", value);
  write(fd, buf, 1);
  close(fd);
}


x86 assembly (clang, -O0):
<set_gpio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe9e(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe8a(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x114(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x114(%rbp),%edi
call   1040 <close@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_gpio>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %esi,%r14d
mov    %edi,%edx
lea    0xea9(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
mov    %eax,%ebp
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1060 <sprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebp,%edi
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <close@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"/sys/class/gpio/gpio%d/value\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define void @set_gpio(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [255 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* %3
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %6
%13 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%14 = load i32, i32* %4
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %6
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%18 = call i32 @write(i32 %16, i8* %17, i32 1)
%19 = load i32, i32* %6
%20 = call i32 @close(i32 %19)
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"/sys/class/gpio/gpio%d/value\00"
@O_WRONLY = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define void @set_gpio(i32 %0, i32 %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = load i32, i32* @O_WRONLY
%7 = call i32 @open(i8* %4, i32 %6)
%8 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%9 = call i32 @write(i32 %7, i8* %4, i32 1)
%10 = tail call i32 @close(i32 %7)
ret void
}