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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int get_clickpad_xinput_id() {
  int id = -1;
  char output_buffer[100];
  FILE *xinput_data =
      popen("xinput --list --id-only 'SynPS/2 Synaptics TouchPad'", "r");
  if (xinput_data != NULL) {
    if (fgets(output_buffer, sizeof(output_buffer), xinput_data) != NULL) {
      id = atoi(output_buffer);
    }
  }
  pclose(xinput_data);
  return id;
}


x86 assembly (clang, -O0):
<get_clickpad_xinput_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0xffffffff,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    0xed5(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     11a1 <get_clickpad_xinput_id+0x61>
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x64,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     119c <get_clickpad_xinput_id+0x5c>
lea    -0x70(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    11a1 <get_clickpad_xinput_id+0x61>
mov    -0x78(%rbp),%rdi
call   1030 <pclose@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_clickpad_xinput_id>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
lea    0xeb3(%rip),%rdi
lea    0xee1(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,%rbx
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1185 <get_clickpad_xinput_id+0x45>
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1185 <get_clickpad_xinput_id+0x45>
mov    %rsp,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <pclose@plt>
mov    %ebp,%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [53 x i8] c"xinput --list --id-only 'SynPS/2 Synaptics TouchPad'\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @get_clickpad_xinput_id() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32*
store i32 -1, i32* %1
%4 = call i32* @popen(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %16
7: ; preds = %0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%9 = load i32*, i32** %3
%10 = call i32* @fgets(i8* %8, i32 100, i32* %9)
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %1
br label %15
15: ; preds = %12, %7
br label %16
16: ; preds = %15, %0
%17 = load i32*, i32** %3
%18 = call i32 @pclose(i32* %17)
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [53 x i8] c"xinput --list --id-only 'SynPS/2 Synaptics TouchPad'\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @get_clickpad_xinput_id() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @popen(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %10, label %5
5: ; preds = %0
%6 = call i32* @fgets(i8* %2, i32 100, i32* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = call i32 @atoi(i8* %2)
br label %10
10: ; preds = %5, %8, %0
%11 = phi i32 [ %9, %8 ], [ -1, %5 ], [ -1, %0 ]
%12 = call i32 @pclose(i32* %3)
ret i32 %11
}