#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 /*<<< orphan*/ *fgets(char *, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char *, int /*<<< orphan*/);
int read_flag(FILE *fp, const char *label, int verbose) {
  const int maxl = 128;
  char line[maxl];
  rewind(fp);
  while ((fgets(line, maxl, fp)) != NULL) {
    if (!strncmp(label, line, strlen(label))) {
      if (verbose)
        printf("%s set\n", label);
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<read_flag>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x80,-0x20(%rbp)
mov    %rsp,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x10(%rbp),%rdx
lea    -0xb0(%rbp),%rdi
mov    $0x80,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1200 <read_flag+0xb0>
mov    -0x18(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xb8(%rbp),%rdi
mov    %eax,%edx
lea    -0xb0(%rbp),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11fb <read_flag+0xab>
cmpl   $0x0,-0x1c(%rbp)
je     11e8 <read_flag+0x98>
mov    -0x18(%rbp),%rsi
lea    0xe1d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    120e <read_flag+0xbe>
jmp    117d <read_flag+0x2d>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_flag>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1060 <rewind@plt>
mov    %rsp,%r15
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x80,%esi
mov    %rbp,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11b6 <read_flag+0x66>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1170 <read_flag+0x20>
xor    %ebp,%ebp
test   %r14d,%r14d
je     11bb <read_flag+0x6b>
lea    0xe54(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
jmp    11bb <read_flag+0x6b>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%s set\0A\00"
define i32 @read_flag(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 128, i32* %8
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %9
%12 = alloca i8, i64 128
%13 = load i32*, i32** %5
%14 = call i32 @rewind(i32* %13)
br label %15
15: ; preds = %32, %3
%16 = load i32*, i32** %5
%17 = call i32* @fgets(i8* %12, i32 128, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %33
19: ; preds = %15
%20 = load i8*, i8** %6
%21 = load i8*, i8** %6
%22 = call i32 @strlen(i8* %21)
%23 = call i32 @strncmp(i8* %20, i8* %12, i32 %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %19
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i8*, i8** %6
%30 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %28, %25
store i32 0, i32* %4
store i32 1, i32* %10
br label %34
32: ; preds = %19
br label %15
33: ; preds = %15
store i32 1, i32* %4
store i32 1, i32* %10
br label %34
34: ; preds = %33, %31
%35 = load i8*, i8** %9
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s set\0A\00"
define i32 @read_flag(i32* nocapture %0, i8* %1, i32 %2) {
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @rewind(i32* %0)
br label %7
7: ; preds = %10, %3
%8 = call i32* @fgets(i8* %5, i32 128, i32* %0)
%9 = icmp eq i32* %8, null
br i1 %9, label %18, label %10
10: ; preds = %7
%11 = call i32 @strlen(i8* %1)
%12 = call i32 @strncmp(i8* %1, i8* %5, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %7
14: ; preds = %10
%15 = icmp eq i32 %2, 0
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %18
18: ; preds = %7, %14, %16
%19 = phi i32 [ 0, %16 ], [ 0, %14 ], [ 1, %7 ]
ret i32 %19
}