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

/* Variables and functions */
scalar_t__ flag_lookup(char *, struct flag_info const *);
char *fread_word(int /*<<< orphan*/ *);
scalar_t__ str_cmp(char *, char *);
int fread_flags(FILE *fp, const struct flag_info *f_list) {
  char *word;
  int flagval = 0;
  word = fread_word(fp);
  while (word != NULL && str_cmp(word, "Endflags")) {
    flagval += flag_lookup(word, f_list);
    word = fread_word(fp);
  }
  return flagval;
}


x86 assembly (clang, -O0):
<fread_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fread_word@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
je     117e <fread_flags+0x4e>
mov    -0x18(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1030 <str_cmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    118e <fread_flags+0x5e>
jmp    11ba <fread_flags+0x8a>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <flag_lookup@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fread_word@plt>
mov    %rax,-0x18(%rbp)
jmp    1154 <fread_flags+0x24>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fread_flags>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
call   1050 <fread_word@plt>
test   %rax,%rax
je     118f <fread_flags+0x5f>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xeac(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <str_cmp@plt>
test   %rax,%rax
je     1191 <fread_flags+0x61>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <flag_lookup@plt>
add    %eax,%ebp
mov    %r12,%rdi
call   1050 <fread_word@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <fread_flags+0x30>
jmp    1191 <fread_flags+0x61>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.flag_info = type { i32 }
@.str = [9 x i8] c"Endflags\00"
define i32 @fread_flags(i32* %0, %struct.flag_info* %1) {
%3 = alloca i32*
%4 = alloca %struct.flag_info*
%5 = alloca i8*
%6 = alloca i32
store i32* %0, i32** %3
store %struct.flag_info* %1, %struct.flag_info** %4
store i32 0, i32* %6
%7 = load i32*, i32** %3
%8 = call i8* @fread_word(i32* %7)
store i8* %8, i8** %5
br label %9
9: ; preds = %18, %2
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i8*, i8** %5
%14 = call i64 @str_cmp(i8* %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%15 = icmp ne i64 %14, 0
br label %16
16: ; preds = %12, %9
%17 = phi i1 [ false, %9 ], [ %15, %12 ]
br i1 %17, label %18, label %28
18: ; preds = %16
%19 = load i8*, i8** %5
%20 = load %struct.flag_info*, %struct.flag_info** %4
%21 = call i64 @flag_lookup(i8* %19, %struct.flag_info* %20)
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = add nsw i64 %23, %21
%25 = trunc i64 %24 to i32
store i32 %25, i32* %6
%26 = load i32*, i32** %3
%27 = call i8* @fread_word(i32* %26)
store i8* %27, i8** %5
br label %9
28: ; preds = %16
%29 = load i32, i32* %6
ret i32 %29
}

LLVM IR (-O2):
%struct.flag_info = type { i32 }
@.str = [9 x i8] c"Endflags\00"
define i32 @fread_flags(i32* %0, %struct.flag_info* %1) {
%3 = tail call i8* @fread_word(i32* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %16, label %5
5: ; preds = %2, %10
%6 = phi i32 [ %13, %10 ], [ 0, %2 ]
%7 = phi i8* [ %14, %10 ], [ %3, %2 ]
%8 = tail call i64 @str_cmp(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %5
%11 = tail call i64 @flag_lookup(i8* %7, %struct.flag_info* %1)
%12 = trunc i64 %11 to i32
%13 = add i32 %6, %12
%14 = tail call i8* @fread_word(i32* %0)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %5
16: ; preds = %5, %10, %2
%17 = phi i32 [ 0, %2 ], [ %13, %10 ], [ %6, %5 ]
ret i32 %17
}