#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*/ sscanf(char *, char *, int *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *strstr(char *, char *);
int nist_get_param_int(char *hdr, char *field, int def_val) {
  char *p;
  int val;
  if (((p = strstr(hdr, field)) != NULL) &&
      (strncmp(" -i ", p + strlen(field), 4) == 0)) {
    sscanf(p + strlen(field) + 4, "%d", &val);
    return val;
  } else
    return def_val;
}


x86 assembly (clang, -O0):
<nist_get_param_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11dc <nist_get_param_int+0x9c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rsi
cltq
add    %rax,%rsi
lea    0xe71(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11dc <nist_get_param_int+0x9c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0x4,%rdi
lea    0xe3d(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e2 <nist_get_param_int+0xa2>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nist_get_param_int>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
call   1060 <strstr@plt>
test   %rax,%rax
je     11a7 <nist_get_param_int+0x67>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rsi
add    %rbp,%rsi
lea    0xe90(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11a7 <nist_get_param_int+0x67>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%rbp,1),%rdi
add    $0x4,%rdi
lea    0xe6d(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1050 <sscanf@plt>
mov    0xc(%rsp),%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c" -i \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @nist_get_param_int(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = load i8*, i8** %6
%12 = call i8* @strstr(i8* %10, i8* %11)
store i8* %12, i8** %8
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %31
14: ; preds = %3
%15 = load i8*, i8** %8
%16 = load i8*, i8** %6
%17 = call i32 @strlen(i8* %16)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %19, i32 4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %14
%23 = load i8*, i8** %8
%24 = load i8*, i8** %6
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = getelementptr inbounds i8, i8* %27, i64 4
%29 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%30 = load i32, i32* %9
store i32 %30, i32* %4
br label %33
31: ; preds = %14, %3
%32 = load i32, i32* %7
store i32 %32, i32* %4
br label %33
33: ; preds = %31, %22
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@.str = [5 x i8] c" -i \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @nist_get_param_int(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %21, label %8
8: ; preds = %3
%9 = tail call i32 @strlen(i8* %1)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %6, i64 %10
%12 = tail call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %11, i32 4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %8
%15 = tail call i32 @strlen(i8* %1)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %6, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 4
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%20 = load i32, i32* %4
br label %21
21: ; preds = %3, %8, %14
%22 = phi i32 [ %20, %14 ], [ %2, %8 ], [ %2, %3 ]
ret i32 %22
}