#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, char *, int, unsigned short);
scalar_t__ strcmp(char *, char *);
void GET_request_handler(struct mg_connection *conn, char *szI2CNumber,
                         char *szPinType, char *szPinNumber) {
  int i2cDevNumber = atoi(szI2CNumber);
  int pinNumber = atoi(szPinNumber);
  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 = 32;
  } 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;
    }
    header = 0;
  } 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,
          "Arduino value for pin %d(%s), from I2C device #%d : %u\r\n",
          pinNumber, szPinType, i2cDevNumber, commandResult);
  send_http_response(conn, 200, response);
}


x86 assembly (clang, -O0):
<GET_request_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     119a <GET_request_handler+0x4a>
cmpl   $0x80,-0x24(%rbp)
jl     11b4 <GET_request_handler+0x64>
mov    -0x8(%rbp),%rdi
mov    $0x1a0,%esi
lea    0xe56(%rip),%rdx
call   1050 <send_http_response@plt>
jmp    1301 <GET_request_handler+0x1b1>
mov    -0x18(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11e8 <GET_request_handler+0x98>
mov    -0x18(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    121f <GET_request_handler+0xcf>
cmpl   $0x0,-0x28(%rbp)
jl     11fc <GET_request_handler+0xac>
cmpl   $0x6,-0x28(%rbp)
jl     1216 <GET_request_handler+0xc6>
mov    -0x8(%rbp),%rdi
mov    $0x1a0,%esi
lea    0xe18(%rip),%rdx
call   1050 <send_http_response@plt>
jmp    1301 <GET_request_handler+0x1b1>
movb   $0x20,-0x29(%rbp)
jmp    12a9 <GET_request_handler+0x159>
mov    -0x18(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1253 <GET_request_handler+0x103>
mov    -0x18(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    128a <GET_request_handler+0x13a>
cmpl   $0x0,-0x28(%rbp)
jl     1267 <GET_request_handler+0x117>
cmpl   $0xe,-0x28(%rbp)
jl     1281 <GET_request_handler+0x131>
mov    -0x8(%rbp),%rdi
mov    $0x1a0,%esi
lea    0xddb(%rip),%rdx
call   1050 <send_http_response@plt>
jmp    1301 <GET_request_handler+0x1b1>
movb   $0x0,-0x29(%rbp)
jmp    12a4 <GET_request_handler+0x154>
mov    -0x8(%rbp),%rdi
mov    $0x1a0,%esi
lea    0xde5(%rip),%rdx
call   1050 <send_http_response@plt>
jmp    1301 <GET_request_handler+0x1b1>
jmp    12a9 <GET_request_handler+0x159>
movzbl -0x29(%rbp),%eax
or     -0x28(%rbp),%eax
mov    %al,-0x2a(%rbp)
movw   $0x0,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x2c(%rbp),%rdx
movzbl -0x2a(%rbp),%esi
call   1030 <i2c_data@plt>
lea    -0x430(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x24(%rbp),%r8d
lea    0xdb4(%rip),%rsi
movzwl -0x2c(%rbp),%r9d
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x430(%rbp),%rdx
mov    $0xc8,%esi
call   1050 <send_http_response@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GET_request_handler>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rdi,%r14
mov    %rsi,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <atoi@plt>
cmp    $0x80,%ebp
jb     118b <GET_request_handler+0x3b>
lea    0xe77(%rip),%rdx
jmp    120a <GET_request_handler+0xba>
mov    %eax,%r15d
lea    0xe8b(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e7 <GET_request_handler+0x97>
lea    0xe79(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e7 <GET_request_handler+0x97>
lea    0xe93(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11fb <GET_request_handler+0xab>
lea    0xec3(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11fb <GET_request_handler+0xab>
lea    0xe9a(%rip),%rdx
jmp    120a <GET_request_handler+0xba>
mov    $0x20,%eax
cmp    $0x6,%r15d
jb     1226 <GET_request_handler+0xd6>
lea    0xe2b(%rip),%rdx
jmp    120a <GET_request_handler+0xba>
xor    %eax,%eax
cmp    $0xe,%r15d
jb     1226 <GET_request_handler+0xd6>
lea    0xe48(%rip),%rdx
mov    %r14,%rdi
mov    $0x1a0,%esi
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <send_http_response@plt>
or     %r15d,%eax
movw   $0x0,0xe(%rsp)
movzbl %al,%esi
lea    0xe(%rsp),%rdx
mov    %ebp,%edi
call   1030 <i2c_data@plt>
movzwl 0xe(%rsp),%r9d
lea    0xe4a(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15d,%edx
mov    %r12,%rcx
mov    %ebp,%r8d
call   1070 <sprintf@plt>
mov    %r14,%rdi
mov    $0xc8,%esi
mov    %rbx,%rdx
call   1050 <send_http_response@plt>
add    $0x410,%rsp
pop    %rbx
pop    %r12
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 = [57 x i8] c"Arduino value for pin %d(%s), from I2C device #%d : %u\0D\0A\00"
define void @GET_request_handler(%struct.mg_connection* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca %struct.mg_connection*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i8
%13 = alloca i16
%14 = alloca [1024 x i8]
store %struct.mg_connection* %0, %struct.mg_connection** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%15 = load i8*, i8** %6
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %9
%17 = load i8*, i8** %8
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %10
%19 = load i32, i32* %9
%20 = icmp slt i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %4
%22 = load i32, i32* %9
%23 = icmp sge i32 %22, 128
br i1 %23, label %24, label %27
24: ; preds = %21, %4
%25 = load %struct.mg_connection*, %struct.mg_connection** %5
%26 = call i32 @send_http_response(%struct.mg_connection* %25, i32 416, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %85
27: ; preds = %21
%28 = load i8*, i8** %7
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i8*, i8** %7
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %45
35: ; preds = %31, %27
%36 = load i32, i32* %10
%37 = icmp slt i32 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %35
%39 = load i32, i32* %10
%40 = icmp sge i32 %39, 6
br i1 %40, label %41, label %44
41: ; preds = %38, %35
%42 = load %struct.mg_connection*, %struct.mg_connection** %5
%43 = call i32 @send_http_response(%struct.mg_connection* %42, i32 416, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
br label %85
44: ; preds = %38
store i8 32, i8* %11
br label %67
45: ; preds = %31
%46 = load i8*, i8** %7
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %53, label %49
49: ; preds = %45
%50 = load i8*, i8** %7
%51 = call i64 @strcmp(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %63
53: ; preds = %49, %45
%54 = load i32, i32* %10
%55 = icmp slt i32 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %53
%57 = load i32, i32* %10
%58 = icmp sge i32 %57, 14
br i1 %58, label %59, label %62
59: ; preds = %56, %53
%60 = load %struct.mg_connection*, %struct.mg_connection** %5
%61 = call i32 @send_http_response(%struct.mg_connection* %60, i32 416, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
br label %85
62: ; preds = %56
store i8 0, i8* %11
br label %66
63: ; preds = %49
%64 = load %struct.mg_connection*, %struct.mg_connection** %5
%65 = call i32 @send_http_response(%struct.mg_connection* %64, i32 416, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %85
66: ; preds = %62
br label %67
67: ; preds = %66, %44
%68 = load i8, i8* %11
%69 = zext i8 %68 to i32
%70 = load i32, i32* %10
%71 = or i32 %69, %70
%72 = trunc i32 %71 to i8
store i8 %72, i8* %12
store i16 0, i16* %13
%73 = load i32, i32* %9
%74 = load i8, i8* %12
%75 = call i32 @i2c_data(i32 %73, i8 zeroext %74, i16* %13)
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%77 = load i32, i32* %10
%78 = load i8*, i8** %7
%79 = load i32, i32* %9
%80 = load i16, i16* %13
%81 = call i32 @sprintf(i8* %76, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.8, i64 0, i64 0), i32 %77, i8* %78, i32 %79, i16 zeroext %80)
%82 = load %struct.mg_connection*, %struct.mg_connection** %5
%83 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%84 = call i32 @send_http_response(%struct.mg_connection* %82, i32 200, i8* %83)
br label %85
85: ; preds = %67, %63, %59, %41, %24
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 = [57 x i8] c"Arduino value for pin %d(%s), from I2C device #%d : %u\0D\0A\00"
define void @GET_request_handler(%struct.mg_connection* %0, i8* nocapture %1, i8* %2, i8* nocapture %3) {
%5 = alloca i16
%6 = alloca [1024 x i8]
%7 = tail call i32 @atoi(i8* %1)
%8 = tail call i32 @atoi(i8* %3)
%9 = icmp ugt i32 %7, 127
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = 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 %44
12: ; preds = %4
%13 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15, %12
%19 = icmp ugt i32 %8, 5
br i1 %19, label %20, label %34
20: ; preds = %18
%21 = 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 %44
22: ; preds = %15
%23 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25, %22
%29 = icmp ugt i32 %8, 13
br i1 %29, label %30, label %34
30: ; preds = %28
%31 = 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 %44
32: ; preds = %25
%33 = 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 %44
34: ; preds = %28, %18
%35 = phi i32 [ 32, %18 ], [ 0, %28 ]
%36 = or i32 %35, %8
%37 = trunc i32 %36 to i8
%38 = bitcast i16* %5 to i8*
store i16 0, i16* %5
%39 = call i32 @i2c_data(i32 %7, i8 zeroext %37, i16* %5)
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%41 = load i16, i16* %5
%42 = call i32 @sprintf(i8* %40, i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.8, i64 0, i64 0), i32 %8, i8* %2, i32 %7, i16 zeroext %41)
%43 = call i32 @send_http_response(%struct.mg_connection* %0, i32 200, i8* %40)
br label %44
44: ; preds = %20, %30, %32, %34, %10
ret void
}