#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*/ http_send(int, char *, ...);
scalar_t__ strcmp(char *, char *);
char *strlen(char *);
int /*<<< orphan*/ system(char *);
int handle_led_cmd(int socket, char *cmd) {
  if (strcmp(cmd, "ledon") == 0)
    system("./led on");
  else
    system("./led off");
  char *body = "OK";
  http_send(socket, "HTTP/1.1 200 OK"
                    "\r\n");
  http_send(socket,
            "Content-Length: %d"
            "\r\n\r\n",
            strlen(body));
  http_send(socket, "%s", body);
  return 200;
}


x86 assembly (clang, -O0):
<handle_led_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    117a <handle_led_cmd+0x3a>
lea    0xe96(%rip),%rdi
call   1040 <system@plt>
jmp    1186 <handle_led_cmd+0x46>
lea    0xe8e(%rip),%rdi
call   1040 <system@plt>
lea    0xe8c(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1060 <http_send@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1060 <http_send@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rdx
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1060 <http_send@plt>
mov    $0xc8,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_led_cmd>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %edi,%ebx
lea    0xeb0(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
lea    0xea4(%rip),%rax
lea    0xea6(%rip),%rdi
cmove  %rax,%rdi
call   1040 <system@plt>
lea    0xea3(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <http_send@plt>
lea    0xe90(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0xe96(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <http_send@plt>
lea    0xe9a(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <http_send@plt>
mov    $0xc8,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"ledon\00"
@.str.1 = [9 x i8] c"./led on\00"
@.str.2 = [10 x i8] c"./led off\00"
@.str.3 = [3 x i8] c"OK\00"
@.str.4 = [18 x i8] c"HTTP/1.1 200 OK\0D\0A\00"
@.str.5 = [23 x i8] c"Content-Length: %d\0D\0A\0D\0A\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @handle_led_cmd(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @system(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %13
11: ; preds = %2
%12 = call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %9
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %5
%14 = load i32, i32* %3
%15 = call i32 (i32, i8*, ...) @http_send(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%16 = load i32, i32* %3
%17 = load i8*, i8** %5
%18 = call i8* @strlen(i8* %17)
%19 = call i32 (i32, i8*, ...) @http_send(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %3
%21 = load i8*, i8** %5
%22 = call i32 (i32, i8*, ...) @http_send(i32 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %21)
ret i32 200
}

LLVM IR (-O2):
@.str = [6 x i8] c"ledon\00"
@.str.1 = [9 x i8] c"./led on\00"
@.str.2 = [10 x i8] c"./led off\00"
@.str.3 = [3 x i8] c"OK\00"
@.str.4 = [18 x i8] c"HTTP/1.1 200 OK\0D\0A\00"
@.str.5 = [23 x i8] c"Content-Length: %d\0D\0A\0D\0A\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @handle_led_cmd(i32 %0, i8* %1) {
%3 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
%5 = select i1 %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
%6 = tail call i32 @system(i8* %5)
%7 = tail call i32 (i32, i8*, ...) @http_send(i32 %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%8 = tail call i8* @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i32 (i32, i8*, ...) @http_send(i32 %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%10 = tail call i32 (i32, i8*, ...) @http_send(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
ret i32 200
}