#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*/ is_io_pin(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int system(char *);
int set_high(int pin) {
  if (!is_io_pin(pin)) {
    printf("Error: pin %d is not allowed i/o pin\n", pin);
    return -1;
  }
  char cmd[255] = {0};
  sprintf(cmd, "gpio write %d 1", pin);
  int rc = system(cmd);
  if (rc != 0) {
    printf("Error: system call returned value %d\n", rc);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_high>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <is_io_pin@plt>
cmp    $0x0,%eax
jne    118a <set_high+0x3a>
mov    -0x8(%rbp),%esi
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <set_high+0xa7>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1050 <memset@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe78(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
je     11f0 <set_high+0xa0>
mov    -0x114(%rbp),%esi
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <set_high+0xa7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_high>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %edi,%ebx
call   1060 <is_io_pin@plt>
test   %eax,%eax
je     11ee <set_high+0xae>
xorps  %xmm0,%xmm0
movups %xmm0,0xef(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe5c(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebx,%edx
call   1050 <sprintf@plt>
mov    %r14,%rdi
call   1030 <system@plt>
test   %eax,%eax
je     1203 <set_high+0xc3>
lea    0xe4c(%rip),%rdi
mov    %eax,%esi
jmp    11f7 <set_high+0xb7>
lea    0xe0b(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
jmp    1205 <set_high+0xc5>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Error: pin %d is not allowed i/o pin\0A\00"
@.str.1 = [16 x i8] c"gpio write %d 1\00"
@.str.2 = [38 x i8] c"Error: system call returned value %d\0A\00"
define i32 @set_high(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [255 x i8]
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = call i32 @is_io_pin(i32 %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 -1, i32* %2
br label %25
12: ; preds = %1
%13 = bitcast [255 x i8]* %4 to i8*
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%15 = load i32, i32* %3
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%18 = call i32 @system(i8* %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = load i32, i32* %5
%23 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %22)
store i32 -1, i32* %2
br label %25
24: ; preds = %12
store i32 0, i32* %2
br label %25
25: ; preds = %24, %21, %9
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [38 x i8] c"Error: pin %d is not allowed i/o pin\0A\00"
@.str.1 = [16 x i8] c"gpio write %d 1\00"
@.str.2 = [38 x i8] c"Error: system call returned value %d\0A\00"
define i32 @set_high(i32 %0) {
%2 = alloca [255 x i8]
%3 = tail call i32 @is_io_pin(i32 %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %16
7: ; preds = %1
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%9 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%10 = call i32 @system(i8* %8)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %14
14: ; preds = %7, %12
%15 = phi i32 [ -1, %12 ], [ 0, %7 ]
br label %16
16: ; preds = %14, %5
%17 = phi i32 [ %15, %14 ], [ -1, %5 ]
ret i32 %17
}