#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*/ hostname;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
scalar_t__ lseek(int, long, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
long seek_magic_and_reposition_for_hostname(int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ write(int, char *, int);
int main(int argc, char **argv) {
  int count, fixit = 0, updates = 0;
  for (count = 1; count < argc; count++) {
    char hostname[65] = {0};
    char *file = argv[count];
    int fd, bytes, length;
    long offset;
    if (strcmp(file, "-f") == 0) {
      fixit = 1;
      continue;
    }
    printf("Filename: %s\n", file);
    if ((fd = open(file, O_RDWR)) < 0) {
      perror("open");
      continue;
    }
    if ((offset = seek_magic_and_reposition_for_hostname(fd)) < 0) {
      close(fd);
      continue;
    }
    if ((bytes = read(fd, hostname, sizeof(hostname))) < 0) {
      perror("read");
      close(fd);
      continue;
    }
    hostname[sizeof(hostname) - 1] = '\0';
    length = strlen(hostname);
    printf("  hostname: %s (%d bytes)\n", hostname, length);
    if (fixit) {
      memset(hostname, 0, length);
      strcpy(hostname, "pcp.qa.org");
      if ((lseek(fd, offset, SEEK_SET)) < 0) {
        perror("lseek2");
        close(fd);
        continue;
      }
      if (write(fd, hostname, length) < 0) {
        perror("write");
        close(fd);
        continue;
      }
      updates++;
    }
    close(fd);
  }
  printf("%d files scanned, %d files updated\n", count - 1 - fixit, updates);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13b0 <main+0x1f0>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1080 <memset@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
lea    0xddb(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    1240 <main+0x80>
movl   $0x1,-0x18(%rbp)
jmp    13a2 <main+0x1e2>
mov    -0x68(%rbp),%rsi
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x68(%rbp),%rdi
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x6c(%rbp)
cmp    $0x0,%eax
jge    1281 <main+0xc1>
lea    0xd9a(%rip),%rdi
call   10d0 <perror@plt>
jmp    13a2 <main+0x1e2>
mov    -0x6c(%rbp),%edi
call   10e0 <seek_magic_and_reposition_for_hostname@plt>
mov    %rax,-0x80(%rbp)
cmp    $0x0,%rax
jge    12a4 <main+0xe4>
mov    -0x6c(%rbp),%edi
call   1090 <close@plt>
jmp    13a2 <main+0x1e2>
mov    -0x6c(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x41,%edx
call   10a0 <read@plt>
mov    %eax,-0x70(%rbp)
cmp    $0x0,%eax
jge    12da <main+0x11a>
lea    0xd4e(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x6c(%rbp),%edi
call   1090 <close@plt>
jmp    13a2 <main+0x1e2>
movb   $0x0,-0x20(%rbp)
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x74(%rbp)
lea    -0x60(%rbp),%rsi
mov    -0x74(%rbp),%edx
lea    0xd23(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
je     139a <main+0x1da>
lea    -0x60(%rbp),%rdi
mov    -0x74(%rbp),%edx
xor    %esi,%esi
call   1080 <memset@plt>
lea    -0x60(%rbp),%rdi
lea    0xd14(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x6c(%rbp),%edi
mov    -0x80(%rbp),%rsi
mov    0x2ca3(%rip),%rax
mov    (%rax),%edx
call   1070 <lseek@plt>
cmp    $0x0,%rax
jge    135f <main+0x19f>
lea    0xcf4(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x6c(%rbp),%edi
call   1090 <close@plt>
jmp    13a2 <main+0x1e2>
mov    -0x6c(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x74(%rbp),%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    1391 <main+0x1d1>
lea    0xcc9(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x6c(%rbp),%edi
call   1090 <close@plt>
jmp    13a2 <main+0x1e2>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x6c(%rbp),%edi
call   1090 <close@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ee <main+0x2e>
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
sub    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xc8b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
cmp    $0x2,%edi
jl     11fe <main+0x3e>
mov    %rsi,%r14
mov    %edi,0x14(%rsp)
mov    %edi,%eax
mov    %rax,0x18(%rsp)
mov    $0x1,%r13d
lea    0x20(%rsp),%rbx
movl   $0x0,0xc(%rsp)
movl   $0x0,0x10(%rsp)
jmp    1237 <main+0x77>
mov    $0x1,%eax
xor    %edx,%edx
xor    %esi,%esi
jmp    13a4 <main+0x1e4>
lea    0xe03(%rip),%rdi
call   10d0 <perror@plt>
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
call   1090 <close@plt>
add    $0x1,%r13
cmp    %r13,0x18(%rsp)
je     1398 <main+0x1d8>
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movb   $0x0,0x60(%rsp)
mov    (%r14,%r13,8),%rbp
mov    %rbp,%rdi
lea    0xd9f(%rip),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     1350 <main+0x190>
lea    0xd8d(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     135d <main+0x19d>
mov    %eax,%r12d
mov    %eax,%edi
call   10e0 <seek_magic_and_reposition_for_hostname@plt>
test   %rax,%rax
js     1220 <main+0x60>
mov    %rax,%r15
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x41,%edx
call   10a0 <read@plt>
test   %eax,%eax
js     120c <main+0x4c>
movb   $0x0,0x60(%rsp)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
lea    0xd3e(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,0xc(%rsp)
je     1220 <main+0x60>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1080 <memset@plt>
mov    %rbx,%rdi
lea    0xd2c(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
mov    %r15,%rsi
call   1070 <lseek@plt>
test   %rax,%rax
js     136e <main+0x1ae>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
test   %rax,%rax
js     1377 <main+0x1b7>
addl   $0x1,0x10(%rsp)
jmp    1220 <main+0x60>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movl   $0x1,0xc(%rsp)
jmp    1228 <main+0x68>
lea    0xcad(%rip),%rdi
call   10d0 <perror@plt>
jmp    1228 <main+0x68>
lea    0xccc(%rip),%rdi
jmp    137e <main+0x1be>
lea    0xcca(%rip),%rdi
call   10d0 <perror@plt>
mov    %r12d,%edi
call   1090 <close@plt>
movl   $0x1,0xc(%rsp)
jmp    1228 <main+0x68>
mov    0x14(%rsp),%eax
mov    0x10(%rsp),%edx
mov    0xc(%rsp),%esi
not    %esi
add    %eax,%esi
lea    0xc9f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-f\00"
@.str.1 = [14 x i8] c"Filename: %s\0A\00"
@O_RDWR = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [27 x i8] c" hostname: %s (%d bytes)\0A\00"
@.str.5 = [11 x i8] c"pcp.qa.org\00"
@SEEK_SET = global i32 0
@.str.6 = [7 x i8] c"lseek2\00"
@.str.7 = [6 x i8] c"write\00"
@.str.8 = [36 x i8] c"%d files scanned, %d files updated\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [65 x i8]
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
store i32 1, i32* %6
br label %15
15: ; preds = %95, %2
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %98
19: ; preds = %15
%20 = bitcast [65 x i8]* %9 to i8*
%21 = load i8**, i8*** %5
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
store i8* %25, i8** %10
%26 = load i8*, i8** %10
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %19
store i32 1, i32* %7
br label %95
30: ; preds = %19
%31 = load i8*, i8** %10
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = load i8*, i8** %10
%34 = load i32, i32* @O_RDWR
%35 = call i32 @open(i8* %33, i32 %34)
store i32 %35, i32* %11
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %30
%38 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %95
39: ; preds = %30
%40 = load i32, i32* %11
%41 = call i64 @seek_magic_and_reposition_for_hostname(i32 %40)
store i64 %41, i64* %14
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i32, i32* %11
%45 = call i32 @close(i32 %44)
br label %95
46: ; preds = %39
%47 = load i32, i32* %11
%48 = getelementptr inbounds [65 x i8], [65 x i8]* %9, i64 0, i64 0
%49 = call i32 @read(i32 %47, i8* %48, i32 65)
store i32 %49, i32* %12
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %46
%52 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%53 = load i32, i32* %11
%54 = call i32 @close(i32 %53)
br label %95
55: ; preds = %46
%56 = getelementptr inbounds [65 x i8], [65 x i8]* %9, i64 0, i64 64
store i8 0, i8* %56
%57 = getelementptr inbounds [65 x i8], [65 x i8]* %9, i64 0, i64 0
%58 = call i32 @strlen(i8* %57)
store i32 %58, i32* %13
%59 = getelementptr inbounds [65 x i8], [65 x i8]* %9, i64 0, i64 0
%60 = load i32, i32* %13
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %59, i32 %60)
%62 = load i32, i32* %7
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %92
64: ; preds = %55
%65 = getelementptr inbounds [65 x i8], [65 x i8]* %9, i64 0, i64 0
%66 = load i32, i32* %13
%67 = call i32 @memset(i8* %65, i32 0, i32 %66)
%68 = getelementptr inbounds [65 x i8], [65 x i8]* %9, i64 0, i64 0
%69 = call i32 @strcpy(i8* %68, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%70 = load i32, i32* %11
%71 = load i64, i64* %14
%72 = load i32, i32* @SEEK_SET
%73 = call i64 @lseek(i32 %70, i64 %71, i32 %72)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %64
%76 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%77 = load i32, i32* %11
%78 = call i32 @close(i32 %77)
br label %95
79: ; preds = %64
%80 = load i32, i32* %11
%81 = getelementptr inbounds [65 x i8], [65 x i8]* %9, i64 0, i64 0
%82 = load i32, i32* %13
%83 = call i64 @write(i32 %80, i8* %81, i32 %82)
%84 = icmp slt i64 %83, 0
br i1 %84, label %85, label %89
85: ; preds = %79
%86 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%87 = load i32, i32* %11
%88 = call i32 @close(i32 %87)
br label %95
89: ; preds = %79
%90 = load i32, i32* %8
%91 = add nsw i32 %90, 1
store i32 %91, i32* %8
br label %92
92: ; preds = %89, %55
%93 = load i32, i32* %11
%94 = call i32 @close(i32 %93)
br label %95
95: ; preds = %92, %85, %75, %51, %43, %37, %29
%96 = load i32, i32* %6
%97 = add nsw i32 %96, 1
store i32 %97, i32* %6
br label %15
98: ; preds = %15
%99 = load i32, i32* %6
%100 = sub nsw i32 %99, 1
%101 = load i32, i32* %7
%102 = sub nsw i32 %100, %101
%103 = load i32, i32* %8
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i32 %102, i32 %103)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"-f\00"
@.str.1 = [14 x i8] c"Filename: %s\0A\00"
@O_RDWR = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [27 x i8] c" hostname: %s (%d bytes)\0A\00"
@.str.5 = [11 x i8] c"pcp.qa.org\00"
@SEEK_SET = global i32 0
@.str.6 = [7 x i8] c"lseek2\00"
@.str.7 = [6 x i8] c"write\00"
@.str.8 = [36 x i8] c"%d files scanned, %d files updated\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [65 x i8]
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %64
5: ; preds = %2
%6 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 64
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %5, %59
%10 = phi i64 [ 1, %5 ], [ %62, %59 ]
%11 = phi i32 [ 0, %5 ], [ %61, %59 ]
%12 = phi i32 [ 0, %5 ], [ %60, %59 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %10
%14 = load i8*, i8** %13
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %59, label %17
17: ; preds = %9
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%19 = load i32, i32* @O_RDWR
%20 = call i32 @open(i8* %14, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %59
24: ; preds = %17
%25 = call i64 @seek_magic_and_reposition_for_hostname(i32 %20)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @close(i32 %20)
br label %59
29: ; preds = %24
%30 = call i32 @read(i32 %20, i8* %6, i32 65)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @close(i32 %20)
br label %59
35: ; preds = %29
store i8 0, i8* %7
%36 = call i32 @strlen(i8* %6)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %6, i32 %36)
%38 = icmp eq i32 %11, 0
br i1 %38, label %56, label %39
39: ; preds = %35
%40 = call i32 @memset(i8* %6, i32 0, i32 %36)
%41 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%42 = load i32, i32* @SEEK_SET
%43 = call i64 @lseek(i32 %20, i64 %25, i32 %42)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %39
%46 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%47 = call i32 @close(i32 %20)
br label %59
48: ; preds = %39
%49 = call i64 @write(i32 %20, i8* %6, i32 %36)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%53 = call i32 @close(i32 %20)
br label %59
54: ; preds = %48
%55 = add nsw i32 %12, 1
br label %56
56: ; preds = %54, %35
%57 = phi i32 [ %55, %54 ], [ %12, %35 ]
%58 = call i32 @close(i32 %20)
br label %59
59: ; preds = %9, %56, %51, %45, %32, %27, %22
%60 = phi i32 [ %12, %22 ], [ %12, %27 ], [ %12, %32 ], [ %12, %45 ], [ %12, %51 ], [ %57, %56 ], [ %12, %9 ]
%61 = phi i32 [ %11, %22 ], [ %11, %27 ], [ %11, %32 ], [ 1, %45 ], [ 1, %51 ], [ %11, %56 ], [ 1, %9 ]
%62 = add nuw nsw i64 %10, 1
%63 = icmp eq i64 %62, %8
br i1 %63, label %64, label %9
64: ; preds = %59, %2
%65 = phi i32 [ 0, %2 ], [ %60, %59 ]
%66 = phi i32 [ 0, %2 ], [ %61, %59 ]
%67 = phi i32 [ 1, %2 ], [ %0, %59 ]
%68 = xor i32 %66, -1
%69 = add i32 %67, %68
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i32 %69, i32 %65)
ret i32 0
}