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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(struct update_blocka *, int, int,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
char *strstr(unsigned char *, char *);
int main(int argc, char *argv[]) {
  FILE *LINKDBFILE;
  struct update_blocka {
    unsigned char sha1[20];
    unsigned char url[200];
    unsigned char linktext[50];
  };
  struct update_blocka nyeurlerPost;
  char *cpointer;
  if (argc < 2) {
    printf("Dette programet tar inn en linkdb fil og lager Brank\n\n\tUsage: "
           "./BrankCalculate linkdb\n");
    exit(0);
  }
  if ((LINKDBFILE = fopen(argv[1], "rb")) == NULL) {
    printf("Cant read\n");
    perror(argv[1]);
    exit(1);
  }
  while (!feof(LINKDBFILE)) {
    fread(&nyeurlerPost, sizeof(nyeurlerPost), 1, LINKDBFILE);
    if ((cpointer = strstr(nyeurlerPost.url, " ")) != NULL) {
      *cpointer = '\0';
      printf("%s\n", nyeurlerPost.url);
    }
    printf("%s\n", nyeurlerPost.url);
  }
  fclose(LINKDBFILE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b8 <main+0x38>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ff <main+0x7f>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1204 <main+0x84>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1222 <main+0xa2>
jmp    12a5 <main+0x125>
lea    -0x128(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x10e,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
lea    -0x128(%rbp),%rdi
add    $0x14,%rdi
lea    0xe17(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x130(%rbp)
cmp    $0x0,%rax
je     1287 <main+0x107>
mov    -0x130(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x128(%rbp),%rsi
add    $0x14,%rsi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x128(%rbp),%rsi
add    $0x14,%rsi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1204 <main+0x84>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x110,%rsp
cmp    $0x1,%edi
jle    1238 <main+0xb8>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe5d(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     124b <main+0xcb>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11d7 <main+0x57>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0x14(%rsp),%r14
mov    %rsp,%r15
jmp    1204 <main+0x84>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11c0 <main+0x40>
mov    %r15,%rdi
mov    $0x10e,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %r14,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11f0 <main+0x70>
movb   $0x0,(%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    11f0 <main+0x70>
lea    0xdce(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xdb1(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%r14),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.update_blocka = type { [20 x i8], [200 x i8], [50 x i8] }
%struct.update_blocka.0 = type opaque
@.str = [87 x i8] c"Dette programet tar inn en linkdb fil og lager Brank\0A\0A\09Usage: ./BrankCalculate linkdb\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [11 x i8] c"Cant read\0A\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.update_blocka
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %27
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @perror(i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %14
br label %28
28: ; preds = %46, %27
%29 = load i32*, i32** %6
%30 = call i32 @feof(i32* %29)
%31 = icmp ne i32 %30, 0
%32 = xor i1 %31, true
br i1 %32, label %33, label %50
33: ; preds = %28
%34 = bitcast %struct.update_blocka* %7 to %struct.update_blocka.0*
%35 = load i32*, i32** %6
%36 = call i32 @fread(%struct.update_blocka.0* %34, i32 270, i32 1, i32* %35)
%37 = getelementptr inbounds %struct.update_blocka, %struct.update_blocka* %7, i32 0, i32 1
%38 = getelementptr inbounds [200 x i8], [200 x i8]* %37, i64 0, i64 0
%39 = call i8* @strstr(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %39, i8** %8
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %46
41: ; preds = %33
%42 = load i8*, i8** %8
store i8 0, i8* %42
%43 = getelementptr inbounds %struct.update_blocka, %struct.update_blocka* %7, i32 0, i32 1
%44 = getelementptr inbounds [200 x i8], [200 x i8]* %43, i64 0, i64 0
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %41, %33
%47 = getelementptr inbounds %struct.update_blocka, %struct.update_blocka* %7, i32 0, i32 1
%48 = getelementptr inbounds [200 x i8], [200 x i8]* %47, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %48)
br label %28
50: ; preds = %28
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
%struct.update_blocka = type { [20 x i8], [200 x i8], [50 x i8] }
%struct.update_blocka.0 = type opaque
@.str.1 = [3 x i8] c"rb\00"
@str = [10 x i8] c"Cant read\00"
@str.5 = [86 x i8] c"Dette programet tar inn en linkdb fil og lager Brank\0A\0A\09Usage: ./BrankCalculate linkdb\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.update_blocka
%4 = getelementptr inbounds %struct.update_blocka, %struct.update_blocka* %3, i64 0, i32 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([86 x i8], [86 x i8]* @str.5, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %20, label %14
14: ; preds = %9
%15 = call i32 @feof(i32* %12)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %35
17: ; preds = %14
%18 = bitcast %struct.update_blocka* %3 to %struct.update_blocka.0*
%19 = getelementptr inbounds %struct.update_blocka, %struct.update_blocka* %3, i64 0, i32 1, i64 0
br label %25
20: ; preds = %9
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%22 = load i8*, i8** %10
%23 = tail call i32 @perror(i8* %22)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %17, %31
%26 = call i32 @fread(%struct.update_blocka.0* %18, i32 270, i32 1, i32* %12)
%27 = call i8* @strchr(i8* %19, i32 32)
%28 = icmp eq i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %25
store i8 0, i8* %27
%30 = call i32 @puts(i8* %19)
br label %31
31: ; preds = %29, %25
%32 = call i32 @puts(i8* %19)
%33 = call i32 @feof(i32* %12)
%34 = icmp eq i32 %33, 0
br i1 %34, label %25, label %35
35: ; preds = %31, %14
%36 = call i32 @fclose(i32* %12)
ret i32 0
}