#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*/ sprintf(char *, char *, int);
int system(char *);
int gpio_set(int nr, int val) {
  char cmdline[200];
  if (val < 0)
    sprintf(cmdline, "/usr/sbin/gpio %d -d i", nr);
  else if (val > 0)
    sprintf(cmdline, "/usr/sbin/gpio %d -d ho 1", nr);
  else
    sprintf(cmdline, "/usr/sbin/gpio %d -d ho 0", nr);
  return system(cmdline);
}


x86 assembly (clang, -O0):
<gpio_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1156 <gpio_set+0x36>
lea    -0xd0(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xeb4(%rip),%rsi
call   1040 <sprintf@plt>
jmp    1196 <gpio_set+0x76>
cmpl   $0x0,-0x8(%rbp)
jle    117b <gpio_set+0x5b>
lea    -0xd0(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xea6(%rip),%rsi
call   1040 <sprintf@plt>
jmp    1191 <gpio_set+0x71>
lea    -0xd0(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xea5(%rip),%rsi
call   1040 <sprintf@plt>
jmp    1196 <gpio_set+0x76>
lea    -0xd0(%rbp),%rdi
call   1030 <system@plt>
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_set>:
push   %rbx
sub    $0xd0,%rsp
test   %esi,%esi
lea    0xf00(%rip),%rax
lea    0xedf(%rip),%rcx
cmove  %rax,%rcx
mov    %edi,%edx
lea    0xebb(%rip),%rsi
cmovns %rcx,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
add    $0xd0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"/usr/sbin/gpio %d -d i\00"
@.str.1 = [26 x i8] c"/usr/sbin/gpio %d -d ho 1\00"
@.str.2 = [26 x i8] c"/usr/sbin/gpio %d -d ho 0\00"
define i32 @gpio_set(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [200 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%10 = load i32, i32* %3
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %24
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%17 = load i32, i32* %3
%18 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %23
19: ; preds = %12
%20 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%21 = load i32, i32* %3
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %19, %15
br label %24
24: ; preds = %23, %8
%25 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%26 = call i32 @system(i8* %25)
ret i32 %26
}

LLVM IR (-O2):
@.str = [23 x i8] c"/usr/sbin/gpio %d -d i\00"
@.str.1 = [26 x i8] c"/usr/sbin/gpio %d -d ho 1\00"
@.str.2 = [26 x i8] c"/usr/sbin/gpio %d -d ho 0\00"
define i32 @gpio_set(i32 %0, i32 %1) {
%3 = alloca [200 x i8]
%4 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %1, 0
%6 = icmp eq i32 %1, 0
%7 = select i1 %6, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0)
%8 = select i1 %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %7
%9 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) %8, i32 %0)
%10 = call i32 @system(i8* %4)
ret i32 %10
}