#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_request_info {
  int dummy;
};

/* Variables and functions */
int atoi(char *);
scalar_t__ is_int(char *);
int str_query_param(struct mg_request_info const *, char const *, char *, int);
int int_query_param(const struct mg_request_info *request_info,
                    const char *param) {
  char buffer[20];
  int res = str_query_param(request_info, param, buffer, 20);
  if (res < 0) {
    return 0;
  }
  if (is_int(buffer)) {
    return atoi(buffer);
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<int_query_param>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
mov    $0x14,%ecx
call   1040 <str_query_param@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    116f <int_query_param+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    119a <int_query_param+0x6a>
lea    -0x30(%rbp),%rdi
call   1030 <is_int@plt>
cmp    $0x0,%rax
je     1193 <int_query_param+0x63>
lea    -0x30(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    119a <int_query_param+0x6a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_query_param>:
push   %rbx
sub    $0x20,%rsp
mov    %rsp,%rdx
mov    $0x14,%ecx
call   1040 <str_query_param@plt>
xor    %ebx,%ebx
test   %eax,%eax
js     115f <int_query_param+0x2f>
mov    %rsp,%rdi
call   1030 <is_int@plt>
test   %rax,%rax
je     115f <int_query_param+0x2f>
mov    %rsp,%rdi
call   1050 <atoi@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.mg_request_info = type { i32 }
define i32 @int_query_param(%struct.mg_request_info* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.mg_request_info*
%5 = alloca i8*
%6 = alloca [20 x i8]
%7 = alloca i32
store %struct.mg_request_info* %0, %struct.mg_request_info** %4
store i8* %1, i8** %5
%8 = load %struct.mg_request_info*, %struct.mg_request_info** %4
%9 = load i8*, i8** %5
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%11 = call i32 @str_query_param(%struct.mg_request_info* %8, i8* %9, i8* %10, i32 20)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 0, i32* %3
br label %23
15: ; preds = %2
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%17 = call i64 @is_int(i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %3
br label %23
22: ; preds = %15
store i32 0, i32* %3
br label %23
23: ; preds = %22, %19, %14
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.mg_request_info = type { i32 }
define i32 @int_query_param(%struct.mg_request_info* %0, i8* %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = call i32 @str_query_param(%struct.mg_request_info* %0, i8* %1, i8* %4, i32 20)
%6 = icmp slt i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = call i64 @is_int(i8* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 @atoi(i8* %4)
br label %12
12: ; preds = %7, %2, %10
%13 = phi i32 [ %11, %10 ], [ 0, %2 ], [ 0, %7 ]
ret i32 %13
}