#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int);
int /*<<< orphan*/ stderr;
int setServoPosition(int servo, int position) {
  FILE *fp = fopen("/dev/servoblaster", "w");
  if (!fp) {
    fprintf(stderr,
            "[-] Can't open servoblaster device to set servo %d (pos %d)\n",
            servo, position);
    return 0;
  }
  char buffer[20];
  snprintf(buffer, 19, "%d=%d\n", servo, position);
  fprintf(stderr, "%s", buffer);
  fputs(buffer, fp);
  fclose(fp);
  return 1;
}


x86 assembly (clang, -O0):
<setServoPosition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe9b(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a9 <setServoPosition+0x59>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fd <setServoPosition+0xad>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    $0x13,%esi
lea    0xe91(%rip),%rdx
call   1040 <snprintf@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xe7f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setServoPosition>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xe9a(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ca <setServoPosition+0x7a>
mov    %rax,%rbx
lea    0xed0(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x13,%esi
mov    %ebp,%ecx
mov    %r14d,%r8d
call   1040 <snprintf@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xeb2(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%ebx
jmp    11e8 <setServoPosition+0x98>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
xor    %ebx,%ebx
mov    %ebp,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/dev/servoblaster\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [61 x i8] c"[-] Can't open servoblaster device to set servo %d (pos %d)\0A\00"
@.str.3 = [7 x i8] c"%d=%d\0A\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @setServoPosition(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [20 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14)
store i32 0, i32* %3
br label %29
16: ; preds = %2
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = call i32 @snprintf(i8* %17, i32 19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %18, i32 %19)
%21 = load i32, i32* @stderr
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%25 = load i32*, i32** %6
%26 = call i32 @fputs(i8* %24, i32* %25)
%27 = load i32*, i32** %6
%28 = call i32 @fclose(i32* %27)
store i32 1, i32* %3
br label %29
29: ; preds = %16, %11
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [18 x i8] c"/dev/servoblaster\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [61 x i8] c"[-] Can't open servoblaster device to set servo %d (pos %d)\0A\00"
@.str.3 = [7 x i8] c"%d=%d\0A\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @setServoPosition(i32 %0, i32 %1) {
%3 = alloca [20 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %1)
br label %16
9: ; preds = %2
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%11 = call i32 @snprintf(i8* %10, i32 19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %0, i32 %1)
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%14 = call i32 @fputs(i8* %10, i32* %4)
%15 = call i32 @fclose(i32* %4)
br label %16
16: ; preds = %9, %6
%17 = phi i32 [ 1, %9 ], [ 0, %6 ]
ret i32 %17
}