#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 */
struct mg_connection {
  int dummy;
};

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ i2c_data(int, unsigned char, unsigned short *);
int /*<<< orphan*/ send_http_response(struct mg_connection *, int, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, char *, int);
scalar_t__ strcmp(char *, char *);
void POST_request_handler(struct mg_connection *conn, char *szI2CNumber,
                          char *szPinType, char *szPinNumber,
                          char *szPinValue) {
  int i2cDevNumber = atoi(szI2CNumber);
  int pinNumber = atoi(szPinNumber);
  int pinValue = atoi(szPinValue);
  if (i2cDevNumber < 0 || i2cDevNumber >= 128) {
    send_http_response(conn, 416, "I2C device number not supported");
    return;
  }
  unsigned char header;
  if (strcmp(szPinType, "A") == 0 || strcmp(szPinType, "a") == 0) {
    if (pinNumber < 0 || pinNumber >= 6) {
      send_http_response(conn, 416,
                         "pin number unsupported for analog operation");
      return;
    }
    header = 96;
  } else if (strcmp(szPinType, "D") == 0 || strcmp(szPinType, "d") == 0) {
    if (pinNumber < 0 || pinNumber >= 14) {
      send_http_response(conn, 416,
                         "pin number unsupported for digital operation");
      return;
    }
    if (pinValue == 0) {
      header = 64;
    } else {
      header = 80;
    }
  } else {
    send_http_response(conn, 416, "Pin type not supported");
    return;
  }
  unsigned char i2cCommand = header | pinNumber;
  unsigned short commandResult = 0;
  i2c_data(i2cDevNumber, i2cCommand, &commandResult);
  char response[1024];
  sprintf(response,
          "Will send you Arduino value %u for pin %u(%s), from I2C bus #%u\r\n",
          pinValue, pinNumber, szPinType, i2cDevNumber);
  send_http_response(conn, 200, response);
}


x86 assembly (clang, -O0):
<POST_request_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     11aa <POST_request_handler+0x5a>
cmpl   $0x80,-0x2c(%rbp)
jl     11c4 <POST_request_handler+0x74>
mov    -0x8(%rbp),%rdi
mov    $0x1a0,%esi
lea    0xe46(%rip),%rdx
call   1050 <send_http_response@plt>
jmp    1322 <POST_request_handler+0x1d2>
mov    -0x18(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11f8 <POST_request_handler+0xa8>
mov    -0x18(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    122f <POST_request_handler+0xdf>
cmpl   $0x0,-0x30(%rbp)
jl     120c <POST_request_handler+0xbc>
cmpl   $0x6,-0x30(%rbp)
jl     1226 <POST_request_handler+0xd6>
mov    -0x8(%rbp),%rdi
mov    $0x1a0,%esi
lea    0xe08(%rip),%rdx
call   1050 <send_http_response@plt>
jmp    1322 <POST_request_handler+0x1d2>
movb   $0x60,-0x35(%rbp)
jmp    12cc <POST_request_handler+0x17c>
mov    -0x18(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1263 <POST_request_handler+0x113>
mov    -0x18(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    12ad <POST_request_handler+0x15d>
cmpl   $0x0,-0x30(%rbp)
jl     1277 <POST_request_handler+0x127>
cmpl   $0xe,-0x30(%rbp)
jl     1291 <POST_request_handler+0x141>
mov    -0x8(%rbp),%rdi
mov    $0x1a0,%esi
lea    0xdcb(%rip),%rdx
call   1050 <send_http_response@plt>
jmp    1322 <POST_request_handler+0x1d2>
cmpl   $0x0,-0x34(%rbp)
jne    12a4 <POST_request_handler+0x154>
movb   $0x40,-0x35(%rbp)
jmp    12a8 <POST_request_handler+0x158>
movb   $0x50,-0x35(%rbp)
jmp    12c7 <POST_request_handler+0x177>
mov    -0x8(%rbp),%rdi
mov    $0x1a0,%esi
lea    0xdc2(%rip),%rdx
call   1050 <send_http_response@plt>
jmp    1322 <POST_request_handler+0x1d2>
jmp    12cc <POST_request_handler+0x17c>
movzbl -0x35(%rbp),%eax
or     -0x30(%rbp),%eax
mov    %al,-0x36(%rbp)
movw   $0x0,-0x38(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x38(%rbp),%rdx
movzbl -0x36(%rbp),%esi
call   1030 <i2c_data@plt>
lea    -0x440(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    -0x2c(%rbp),%r9d
lea    0xd8e(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x440(%rbp),%rdx
mov    $0xc8,%esi
call   1050 <send_http_response@plt>
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<POST_request_handler>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %r8,%rbx
mov    %rcx,%rbp
mov    %rdx,%r13
mov    %rdi,%r14
mov    %rsi,%rdi
call   1060 <atoi@plt>
mov    %eax,%r12d
mov    %rbp,%rdi
call   1060 <atoi@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1060 <atoi@plt>
cmp    $0x80,%r12d
jb     119d <POST_request_handler+0x4d>
lea    0xe65(%rip),%rdx
jmp    1219 <POST_request_handler+0xc9>
mov    %eax,%ebx
lea    0xe7a(%rip),%rsi
mov    %r13,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11f8 <POST_request_handler+0xa8>
lea    0xe68(%rip),%rsi
mov    %r13,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11f8 <POST_request_handler+0xa8>
lea    0xe82(%rip),%rsi
mov    %r13,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     120c <POST_request_handler+0xbc>
lea    0xeb2(%rip),%rsi
mov    %r13,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     120c <POST_request_handler+0xbc>
lea    0xe89(%rip),%rdx
jmp    1219 <POST_request_handler+0xc9>
mov    $0x60,%eax
cmp    $0x6,%r15d
jb     1244 <POST_request_handler+0xf4>
lea    0xe1a(%rip),%rdx
jmp    1219 <POST_request_handler+0xc9>
cmp    $0xe,%r15d
jb     1237 <POST_request_handler+0xe7>
lea    0xe39(%rip),%rdx
mov    %r14,%rdi
mov    $0x1a0,%esi
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <send_http_response@plt>
xor    %eax,%eax
test   %ebx,%ebx
setne  %al
shl    $0x4,%eax
or     $0x40,%eax
or     %r15d,%eax
movw   $0x0,0xe(%rsp)
movzbl %al,%esi
lea    0xe(%rsp),%rdx
mov    %r12d,%edi
call   1030 <i2c_data@plt>
lea    0xe31(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    %r13,%r8
mov    %r12d,%r9d
call   1070 <sprintf@plt>
mov    %r14,%rdi
mov    $0xc8,%esi
mov    %rbp,%rdx
call   1050 <send_http_response@plt>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mg_connection = type { i32 }
@.str = [32 x i8] c"I2C device number not supported\00"
@.str.1 = [2 x i8] c"A\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [44 x i8] c"pin number unsupported for analog operation\00"
@.str.4 = [2 x i8] c"D\00"
@.str.5 = [2 x i8] c"d\00"
@.str.6 = [45 x i8] c"pin number unsupported for digital operation\00"
@.str.7 = [23 x i8] c"Pin type not supported\00"
@.str.8 = [66 x i8] c"Will send you Arduino value %u for pin %u(%s), from I2C bus #%u\0D\0A\00"
define void @POST_request_handler(%struct.mg_connection* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca %struct.mg_connection*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
%15 = alloca i8
%16 = alloca i16
%17 = alloca [1024 x i8]
store %struct.mg_connection* %0, %struct.mg_connection** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%18 = load i8*, i8** %7
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %11
%20 = load i8*, i8** %9
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %12
%22 = load i8*, i8** %10
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %13
%24 = load i32, i32* %11
%25 = icmp slt i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %5
%27 = load i32, i32* %11
%28 = icmp sge i32 %27, 128
br i1 %28, label %29, label %32
29: ; preds = %26, %5
%30 = load %struct.mg_connection*, %struct.mg_connection** %6
%31 = call i32 @send_http_response(%struct.mg_connection* %30, i32 416, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %95
32: ; preds = %26
%33 = load i8*, i8** %8
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %32
%37 = load i8*, i8** %8
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %50
40: ; preds = %36, %32
%41 = load i32, i32* %12
%42 = icmp slt i32 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = load i32, i32* %12
%45 = icmp sge i32 %44, 6
br i1 %45, label %46, label %49
46: ; preds = %43, %40
%47 = load %struct.mg_connection*, %struct.mg_connection** %6
%48 = call i32 @send_http_response(%struct.mg_connection* %47, i32 416, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
br label %95
49: ; preds = %43
store i8 96, i8* %14
br label %77
50: ; preds = %36
%51 = load i8*, i8** %8
%52 = call i64 @strcmp(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %58, label %54
54: ; preds = %50
%55 = load i8*, i8** %8
%56 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %73
58: ; preds = %54, %50
%59 = load i32, i32* %12
%60 = icmp slt i32 %59, 0
br i1 %60, label %64, label %61
61: ; preds = %58
%62 = load i32, i32* %12
%63 = icmp sge i32 %62, 14
br i1 %63, label %64, label %67
64: ; preds = %61, %58
%65 = load %struct.mg_connection*, %struct.mg_connection** %6
%66 = call i32 @send_http_response(%struct.mg_connection* %65, i32 416, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
br label %95
67: ; preds = %61
%68 = load i32, i32* %13
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %67
store i8 64, i8* %14
br label %72
71: ; preds = %67
store i8 80, i8* %14
br label %72
72: ; preds = %71, %70
br label %76
73: ; preds = %54
%74 = load %struct.mg_connection*, %struct.mg_connection** %6
%75 = call i32 @send_http_response(%struct.mg_connection* %74, i32 416, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %95
76: ; preds = %72
br label %77
77: ; preds = %76, %49
%78 = load i8, i8* %14
%79 = zext i8 %78 to i32
%80 = load i32, i32* %12
%81 = or i32 %79, %80
%82 = trunc i32 %81 to i8
store i8 %82, i8* %15
store i16 0, i16* %16
%83 = load i32, i32* %11
%84 = load i8, i8* %15
%85 = call i32 @i2c_data(i32 %83, i8 zeroext %84, i16* %16)
%86 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%87 = load i32, i32* %13
%88 = load i32, i32* %12
%89 = load i8*, i8** %8
%90 = load i32, i32* %11
%91 = call i32 @sprintf(i8* %86, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.8, i64 0, i64 0), i32 %87, i32 %88, i8* %89, i32 %90)
%92 = load %struct.mg_connection*, %struct.mg_connection** %6
%93 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%94 = call i32 @send_http_response(%struct.mg_connection* %92, i32 200, i8* %93)
br label %95
95: ; preds = %77, %73, %64, %46, %29
ret void
}

LLVM IR (-O2):
%struct.mg_connection = type { i32 }
@.str = [32 x i8] c"I2C device number not supported\00"
@.str.1 = [2 x i8] c"A\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [44 x i8] c"pin number unsupported for analog operation\00"
@.str.4 = [2 x i8] c"D\00"
@.str.5 = [2 x i8] c"d\00"
@.str.6 = [45 x i8] c"pin number unsupported for digital operation\00"
@.str.7 = [23 x i8] c"Pin type not supported\00"
@.str.8 = [66 x i8] c"Will send you Arduino value %u for pin %u(%s), from I2C bus #%u\0D\0A\00"
define void @POST_request_handler(%struct.mg_connection* %0, i8* nocapture %1, i8* %2, i8* nocapture %3, i8* nocapture %4) {
%6 = alloca i16
%7 = alloca [1024 x i8]
%8 = tail call i32 @atoi(i8* %1)
%9 = tail call i32 @atoi(i8* %3)
%10 = tail call i32 @atoi(i8* %4)
%11 = icmp ugt i32 %8, 127
br i1 %11, label %12, label %14
12: ; preds = %5
%13 = tail call i32 @send_http_response(%struct.mg_connection* %0, i32 416, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %48
14: ; preds = %5
%15 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17, %14
%21 = icmp ugt i32 %9, 5
br i1 %21, label %22, label %39
22: ; preds = %20
%23 = tail call i32 @send_http_response(%struct.mg_connection* %0, i32 416, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
br label %48
24: ; preds = %17
%25 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %27, %24
%31 = icmp ugt i32 %9, 13
br i1 %31, label %32, label %34
32: ; preds = %30
%33 = tail call i32 @send_http_response(%struct.mg_connection* %0, i32 416, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
br label %48
34: ; preds = %30
%35 = icmp eq i32 %10, 0
%36 = select i1 %35, i32 64, i32 80
br label %39
37: ; preds = %27
%38 = tail call i32 @send_http_response(%struct.mg_connection* %0, i32 416, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %48
39: ; preds = %34, %20
%40 = phi i32 [ 96, %20 ], [ %36, %34 ]
%41 = or i32 %40, %9
%42 = trunc i32 %41 to i8
%43 = bitcast i16* %6 to i8*
store i16 0, i16* %6
%44 = call i32 @i2c_data(i32 %8, i8 zeroext %42, i16* %6)
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%46 = call i32 @sprintf(i8* %45, i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.8, i64 0, i64 0), i32 %10, i32 %9, i8* %2, i32 %8)
%47 = call i32 @send_http_response(%struct.mg_connection* %0, i32 200, i8* %45)
br label %48
48: ; preds = %22, %32, %37, %39, %12
ret void
}