#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 ssize_t;
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ execvp(char *, char **);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ mouseloc(int *, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ process_args(char *, char **);
int read(int, char *, int);
int /*<<< orphan*/ set_env_coords(int, int);
int /*<<< orphan*/ set_environment();
int /*<<< orphan*/ stderr;
void process_click(int fd) {
  char buf[4096];
  char *args[40];
  int x, y;
  ssize_t n_bytes;
  pid_t childpid;
  n_bytes = read(fd, buf, 4096);
  if (n_bytes < 0) {
    perror("lemonbar click read");
  }
  if (buf[n_bytes - 1] == '\n') {
    buf[n_bytes - 1] = '\0';
  } else {
    buf[n_bytes] = 0;
  }
  if ((childpid = fork()) == -1) {
    perror("fork");
    return;
  }
  if (childpid == 0) {
    ;
    process_args(buf, args);
    mouseloc(&x, &y);
    if (x != -1 && y != -1) {
      set_env_coords(x, y);
    } else {
      fprintf(stderr, "mouse location determination failed\n");
    }
    set_environment();
    execvp(args[0], args);
  } else {
    return;
  };
}


x86 assembly (clang, -O0):
<process_click>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1160,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,-0x115c(%rbp)
cmpl   $0x0,-0x115c(%rbp)
jge    11d1 <process_click+0x41>
lea    0xe34(%rip),%rdi
call   1080 <perror@plt>
mov    -0x115c(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x1010(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1205 <process_click+0x75>
mov    -0x115c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x1010(%rbp,%rax,1)
jmp    1214 <process_click+0x84>
movslq -0x115c(%rbp),%rax
movb   $0x0,-0x1010(%rbp,%rax,1)
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x1160(%rbp)
cmp    $0xffffffff,%eax
jne    123b <process_click+0xab>
lea    0xde3(%rip),%rdi
call   1080 <perror@plt>
jmp    12d7 <process_click+0x147>
cmpl   $0x0,-0x1160(%rbp)
jne    12d2 <process_click+0x142>
lea    -0x1010(%rbp),%rdi
lea    -0x1150(%rbp),%rsi
call   10a0 <process_args@plt>
lea    -0x1154(%rbp),%rdi
lea    -0x1158(%rbp),%rsi
call   1040 <mouseloc@plt>
cmpl   $0xffffffff,-0x1154(%rbp)
je     129e <process_click+0x10e>
cmpl   $0xffffffff,-0x1158(%rbp)
je     129e <process_click+0x10e>
mov    -0x1154(%rbp),%edi
mov    -0x1158(%rbp),%esi
call   1030 <set_env_coords@plt>
jmp    12b3 <process_click+0x123>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
lea    0xd6b(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1050 <set_environment@plt>
mov    -0x1150(%rbp),%rdi
lea    -0x1150(%rbp),%rsi
call   1090 <execvp@plt>
jmp    12d7 <process_click+0x147>
jmp    12d7 <process_click+0x147>
add    $0x1160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_click>:
push   %rbx
sub    $0x1150,%rsp
lea    0x150(%rsp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
js     126b <process_click+0xdb>
movslq %ebx,%rax
lea    (%rsp,%rax,1),%rcx
add    $0x14f,%rcx
cmpb   $0xa,0x14f(%rsp,%rax,1)
0a
lea    0x150(%rsp,%rax,1),%rax
cmove  %rcx,%rax
movb   $0x0,(%rax)
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     11fd <process_click+0x6d>
cmp    $0xffffffff,%eax
jne    1262 <process_click+0xd2>
lea    0xe24(%rip),%rdi
add    $0x1150,%rsp
pop    %rbx
jmp    1080 <perror@plt>
lea    0x150(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10a0 <process_args@plt>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1040 <mouseloc@plt>
mov    0xc(%rsp),%edi
cmp    $0xffffffff,%edi
je     1237 <process_click+0xa7>
mov    0x8(%rsp),%esi
cmp    $0xffffffff,%esi
je     1237 <process_click+0xa7>
call   1030 <set_env_coords@plt>
jmp    124c <process_click+0xbc>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    0xdd2(%rip),%rsi
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1050 <set_environment@plt>
mov    0x10(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1090 <execvp@plt>
add    $0x1150,%rsp
pop    %rbx
ret
lea    0xd8e(%rip),%rdi
call   1080 <perror@plt>
jmp    11b4 <process_click+0x24>

LLVM IR (-O0):
@.str = [20 x i8] c"lemonbar click read\00"
@.str.1 = [5 x i8] c"fork\00"
@stderr = global i32 0
@.str.2 = [37 x i8] c"mouse location determination failed\0A\00"
define void @process_click(i32 %0) {
%2 = alloca i32
%3 = alloca [4096 x i8]
%4 = alloca [40 x i8*]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %2
%9 = load i32, i32* %2
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 4096)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
%17 = load i32, i32* %7
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %29
24: ; preds = %16
%25 = load i32, i32* %7
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %27
store i8 0, i8* %28
br label %33
29: ; preds = %16
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %29, %24
%34 = call i32 (...) @fork()
store i32 %34, i32* %8
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %65
38: ; preds = %33
%39 = load i32, i32* %8
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %64
41: ; preds = %38
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%43 = getelementptr inbounds [40 x i8*], [40 x i8*]* %4, i64 0, i64 0
%44 = call i32 @process_args(i8* %42, i8** %43)
%45 = call i32 @mouseloc(i32* %5, i32* %6)
%46 = load i32, i32* %5
%47 = icmp ne i32 %46, -1
br i1 %47, label %48, label %55
48: ; preds = %41
%49 = load i32, i32* %6
%50 = icmp ne i32 %49, -1
br i1 %50, label %51, label %55
51: ; preds = %48
%52 = load i32, i32* %5
%53 = load i32, i32* %6
%54 = call i32 @set_env_coords(i32 %52, i32 %53)
br label %58
55: ; preds = %48, %41
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %58
58: ; preds = %55, %51
%59 = call i32 (...) @set_environment()
%60 = getelementptr inbounds [40 x i8*], [40 x i8*]* %4, i64 0, i64 0
%61 = load i8*, i8** %60
%62 = getelementptr inbounds [40 x i8*], [40 x i8*]* %4, i64 0, i64 0
%63 = call i32 @execvp(i8* %61, i8** %62)
br label %65
64: ; preds = %38
br label %65
65: ; preds = %36, %64, %58
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"lemonbar click read\00"
@.str.1 = [5 x i8] c"fork\00"
@stderr = global i32 0
@.str.2 = [37 x i8] c"mouse location determination failed\0A\00"
define void @process_click(i32 %0) {
%2 = alloca [4096 x i8]
%3 = alloca [40 x i8*]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%7 = bitcast [40 x i8*]* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = call i32 @read(i32 %0, i8* %6, i32 4096)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = add nsw i32 %10, -1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 10
%20 = sext i32 %10 to i64
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 %20
%22 = select i1 %19, i8* %17, i8* %21
store i8 0, i8* %22
%23 = tail call i32 (...) @fork()
switch i32 %23, label %44 [
i32 -1, label %24
i32 0, label %26
]
24: ; preds = %14
%25 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %44
26: ; preds = %14
%27 = getelementptr inbounds [40 x i8*], [40 x i8*]* %3, i64 0, i64 0
%28 = call i32 @process_args(i8* %6, i8** %27)
%29 = call i32 @mouseloc(i32* %4, i32* %5)
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, -1
%32 = load i32, i32* %5
%33 = icmp ne i32 %32, -1
%34 = select i1 %31, i1 %33, i1 false
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = call i32 @set_env_coords(i32 %30, i32 %32)
br label %40
37: ; preds = %26
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %37, %35
%41 = call i32 (...) @set_environment()
%42 = load i8*, i8** %27
%43 = call i32 @execvp(i8* %42, i8** %27)
br label %44
44: ; preds = %14, %40, %24
ret void
}