#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int ignore_whitespace(int /*<<< orphan*/ *);
int read_int(int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ sysbuild_warning(char *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int read_opt_val(FILE *config_fp, int *value) {
  int c;
  if ((c = ignore_whitespace(config_fp)) != '[') {
    ungetc(c, config_fp);
    return 1;
  }
  if (read_int(config_fp, value) != 1) {
    return 0;
  }
  if ((c = ignore_whitespace(config_fp)) != ']') {
    sysbuild_warning("No closing bracket for optional argument");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<read_opt_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ignore_whitespace@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x5b,%eax
je     117d <read_opt_val+0x3d>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <ungetc@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d3 <read_opt_val+0x93>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <read_int@plt>
cmp    $0x1,%eax
je     119f <read_opt_val+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <read_opt_val+0x93>
mov    -0x10(%rbp),%rdi
call   1030 <ignore_whitespace@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x5d,%eax
je     11cc <read_opt_val+0x8c>
lea    0xe45(%rip),%rdi
call   1060 <sysbuild_warning@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <read_opt_val+0x93>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_opt_val>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <ignore_whitespace@plt>
cmp    $0x5b,%eax
jne    118c <read_opt_val+0x4c>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <read_int@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
jne    119b <read_opt_val+0x5b>
mov    %rbx,%rdi
call   1030 <ignore_whitespace@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x5d,%ecx
je     119b <read_opt_val+0x5b>
lea    0xe7d(%rip),%rdi
call   1060 <sysbuild_warning@plt>
xor    %eax,%eax
jmp    119b <read_opt_val+0x5b>
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <ungetc@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [41 x i8] c"No closing bracket for optional argument\00"
define i32 @read_opt_val(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%7 = load i32*, i32** %4
%8 = call i32 @ignore_whitespace(i32* %7)
store i32 %8, i32* %6
%9 = icmp ne i32 %8, 91
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* %6
%12 = load i32*, i32** %4
%13 = call i32 @ungetc(i32 %11, i32* %12)
store i32 1, i32* %3
br label %27
14: ; preds = %2
%15 = load i32*, i32** %4
%16 = load i32*, i32** %5
%17 = call i32 @read_int(i32* %15, i32* %16)
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 0, i32* %3
br label %27
20: ; preds = %14
%21 = load i32*, i32** %4
%22 = call i32 @ignore_whitespace(i32* %21)
store i32 %22, i32* %6
%23 = icmp ne i32 %22, 93
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @sysbuild_warning(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %27
26: ; preds = %20
store i32 1, i32* %3
br label %27
27: ; preds = %26, %24, %19, %10
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [41 x i8] c"No closing bracket for optional argument\00"
define i32 @read_opt_val(i32* %0, i32* %1) {
%3 = tail call i32 @ignore_whitespace(i32* %0)
%4 = icmp eq i32 %3, 91
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @ungetc(i32 %3, i32* %0)
br label %15
7: ; preds = %2
%8 = tail call i32 @read_int(i32* %0, i32* %1)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = tail call i32 @ignore_whitespace(i32* %0)
%12 = icmp eq i32 %11, 93
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @sysbuild_warning(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %10, %7, %13, %5
%16 = phi i32 [ 1, %5 ], [ 0, %13 ], [ 0, %7 ], [ 1, %10 ]
ret i32 %16
}