#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*/ fatal_error(int /*<<< orphan*/, char *, char *);
int sscanf(char *, char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int get_header(char line[], char *header) {
  char temp[4096], *dum;
  strcpy(temp, line);
  dum = strchr(temp, '[');
  if (dum == NULL)
    return 0;
  dum[0] = ' ';
  dum = strchr(temp, ']');
  if (dum == NULL) {
    fatal_error(0, "header is not terminated on line:\n'%s'\n", line);
    return 0;
  }
  dum[0] = '\0';
  if (sscanf(temp, "%s%*s", header) != 1)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<get_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x1020(%rbp),%rdi
mov    $0x5b,%esi
call   1040 <strchr@plt>
mov    %rax,-0x1028(%rbp)
cmpq   $0x0,-0x1028(%rbp)
jne    1195 <get_header+0x55>
movl   $0x0,-0x4(%rbp)
jmp    1220 <get_header+0xe0>
mov    -0x1028(%rbp),%rax
movb   $0x20,(%rax)
lea    -0x1020(%rbp),%rdi
mov    $0x5d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x1028(%rbp)
cmpq   $0x0,-0x1028(%rbp)
jne    11e3 <get_header+0xa3>
mov    -0x10(%rbp),%rdx
xor    %edi,%edi
lea    0xe2e(%rip),%rsi
call   1050 <fatal_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1220 <get_header+0xe0>
mov    -0x1028(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe29(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     1219 <get_header+0xd9>
movl   $0x0,-0x4(%rbp)
jmp    1220 <get_header+0xe0>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_header>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    $0x5b,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a6 <get_header+0x66>
movb   $0x20,(%rax)
mov    %rsp,%rdi
mov    $0x5d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11aa <get_header+0x6a>
movb   $0x0,(%rax)
lea    0xe98(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
call   1060 <sscanf@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
sete   %bpl
jmp    11bd <get_header+0x7d>
xor    %ebp,%ebp
jmp    11bd <get_header+0x7d>
lea    0xe4f(%rip),%rsi
xor    %ebp,%ebp
xor    %edi,%edi
mov    %rbx,%rdx
call   1050 <fatal_error@plt>
mov    %ebp,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"header is not terminated on line:\0A'%s'\0A\00"
@.str.1 = [6 x i8] c"%s%*s\00"
define i32 @get_header(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [4096 x i8]
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = call i32 @strcpy(i8* %8, i8* %9)
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%12 = call i8* @strchr(i8* %11, i8 signext 91)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 0, i32* %3
br label %35
16: ; preds = %2
%17 = load i8*, i8** %7
%18 = getelementptr inbounds i8, i8* %17, i64 0
store i8 32, i8* %18
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%20 = call i8* @strchr(i8* %19, i8 signext 93)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i8*, i8** %4
%25 = call i32 @fatal_error(i32 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %24)
store i32 0, i32* %3
br label %35
26: ; preds = %16
%27 = load i8*, i8** %7
%28 = getelementptr inbounds i8, i8* %27, i64 0
store i8 0, i8* %28
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%30 = load i8*, i8** %5
%31 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = icmp ne i32 %31, 1
br i1 %32, label %33, label %34
33: ; preds = %26
store i32 0, i32* %3
br label %35
34: ; preds = %26
store i32 1, i32* %3
br label %35
35: ; preds = %34, %33, %23, %15
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [40 x i8] c"header is not terminated on line:\0A'%s'\0A\00"
@.str.1 = [6 x i8] c"%s%*s\00"
define i32 @get_header(i8* %0, i8* %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* %0)
%6 = call i8* @strchr(i8* %4, i8 signext 91)
%7 = icmp eq i8* %6, null
br i1 %7, label %17, label %8
8: ; preds = %2
store i8 32, i8* %6
%9 = call i8* @strchr(i8* %4, i8 signext 93)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @fatal_error(i32 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %17
13: ; preds = %8
store i8 0, i8* %9
%14 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%15 = icmp eq i32 %14, 1
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %13, %2, %11
%18 = phi i32 [ 0, %11 ], [ 0, %2 ], [ %16, %13 ]
ret i32 %18
}