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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ gyldig_url(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main(int argc, char *argv[]) {
  FILE *UPDATEFILE;
  char buf[1024];
  int len;
  if (argc < 2) {
    printf("Usage: ./addanchors anchorfile\n\n\tanchorfile, fil med tekster på "
           "linker\n\n");
    exit(1);
  }
  if ((UPDATEFILE = fopen(argv[1], "rb")) == NULL) {
    printf("Cant read anchorfile ");
    perror(argv[1]);
    exit(1);
  }
  while (fgets(buf, sizeof(buf), UPDATEFILE) != NULL) {
    len = strlen(buf);
    --len;
    if (buf[len] == '\n') {
      buf[len] = '\0';
      if (gyldig_url(buf)) {
        printf("ok: \"%s\"\n", buf);
      } else {
        printf("bad: \"%s\"\n", buf);
      }
    } else {
      printf("overflowed buffer. Las char vas char nr %i as \"%c\"\n", len,
             buf[len]);
    }
  }
  fclose(UPDATEFILE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11bb <main+0x3b>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe80(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1202 <main+0x82>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1207 <main+0x87>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12e0 <main+0x160>
lea    -0x420(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x424(%rbp)
mov    -0x424(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x424(%rbp)
movslq -0x424(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    12b8 <main+0x138>
movslq -0x424(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rdi
call   1030 <gyldig_url@plt>
cmp    $0x0,%rax
je     129e <main+0x11e>
lea    -0x420(%rbp),%rsi
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12b3 <main+0x133>
lea    -0x420(%rbp),%rsi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12db <main+0x15b>
mov    -0x424(%rbp),%esi
movslq -0x424(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%edx
ff
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1207 <main+0x87>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
cmp    $0x1,%edi
jle    1278 <main+0xe8>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe49(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     128e <main+0xfe>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     125d <main+0xcd>
mov    %rsp,%rbx
lea    0xe38(%rip),%r15
lea    0xe27(%rip),%r12
lea    0xe35(%rip),%r13
jmp    121f <main+0x8f>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     125d <main+0xcd>
mov    %rbx,%rdi
call   1060 <strlen@plt>
movslq %eax,%rsi
movsbl -0x1(%rsp,%rsi,1),%edx
add    $0xffffffffffffffff,%rsi
cmp    $0xa,%edx
jne    1200 <main+0x70>
movb   $0x0,(%rsp,%rsi,1)
mov    %rbx,%rdi
call   1040 <gyldig_url@plt>
test   %rax,%rax
je     124e <main+0xbe>
mov    %r12,%rdi
jmp    1251 <main+0xc1>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    120a <main+0x7a>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xde3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd6e(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%rbx),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [74 x i8] c"Usage: ./addanchors anchorfile\0A\0A\09anchorfile, fil med tekster p\C3\A5 linker\0A\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [22 x i8] c"Cant read anchorfile \00"
@.str.3 = [10 x i8] c"ok: \22%s\22\0A\00"
@.str.4 = [11 x i8] c"bad: \22%s\22\0A\00"
@.str.5 = [52 x i8] c"overflowed buffer. Las char vas char nr %i as \22%c\22\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i32
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 ([74 x i8], [74 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
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 ([22 x i8], [22 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 = %66, %27
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%30 = load i32*, i32** %6
%31 = call i32* @fgets(i8* %29, i32 1024, i32* %30)
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %67
33: ; preds = %28
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
store i32 %35, i32* %8
%36 = load i32, i32* %8
%37 = add nsw i32 %36, -1
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 10
br i1 %43, label %44, label %58
44: ; preds = %33
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %46
store i8 0, i8* %47
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%49 = call i64 @gyldig_url(i8* %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %44
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %52)
br label %57
54: ; preds = %44
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %54, %51
br label %66
58: ; preds = %33
%59 = load i32, i32* %8
%60 = load i32, i32* %8
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i32 %59, i32 %64)
br label %66
66: ; preds = %58, %57
br label %28
67: ; preds = %28
%68 = load i32*, i32** %6
%69 = call i32 @fclose(i32* %68)
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [22 x i8] c"Cant read anchorfile \00"
@.str.3 = [10 x i8] c"ok: \22%s\22\0A\00"
@.str.4 = [11 x i8] c"bad: \22%s\22\0A\00"
@.str.5 = [52 x i8] c"overflowed buffer. Las char vas char nr %i as \22%c\22\0A\00"
@str = [73 x i8] c"Usage: ./addanchors anchorfile\0A\0A\09anchorfile, fil med tekster p\C3\A5 linker\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 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 ([73 x i8], [73 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
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 %17, label %14
14: ; preds = %9
%15 = call i32* @fgets(i8* %4, i32 1024, i32* %12)
%16 = icmp eq i32* %15, null
br i1 %16, label %42, label %22
17: ; preds = %9
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%19 = load i8*, i8** %10
%20 = tail call i32 @perror(i8* %19)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %14, %39
%23 = call i32 @strlen(i8* %4)
%24 = add nsw i32 %23, -1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 10
br i1 %28, label %29, label %36
29: ; preds = %22
store i8 0, i8* %26
%30 = call i64 @gyldig_url(i8* %4)
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %39
34: ; preds = %29
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %39
36: ; preds = %22
%37 = sext i8 %27 to i32
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i32 %24, i32 %37)
br label %39
39: ; preds = %32, %34, %36
%40 = call i32* @fgets(i8* %4, i32 1024, i32* %12)
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %22
42: ; preds = %39, %14
%43 = call i32 @fclose(i32* %12)
ret i32 0
}