#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*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main(int argc, char *argv[]) {
  char buffer[5] = {0};
  int count = 0;
  int fd, i, k;
  if (argc != 2) {
    printf("Usage: %s <file>\n", argv[0]);
    exit(-1);
  }
  fd = open(argv[1], O_RDONLY);
  do {
    if (!(fd != -1)) {
      perror("open");
      exit(-1);
    }
  } while (0);
  for (i = 3; i >= 0; i--) {
    k = lseek(fd, i, SEEK_SET);
    do {
      if (!(k != -1)) {
        perror("lseek");
        exit(-1);
      }
    } while (0);
    k = read(fd, &buffer[i], sizeof(char));
    do {
      if (!(k == sizeof(char))) {
        perror("read");
        exit(-1);
      }
    } while (0);
  }
  if (buffer[0] == 'b')
    count++;
  if (buffer[1] == 'a')
    count++;
  if (buffer[2] == 'd')
    count++;
  if (buffer[3] == '!')
    count++;
  if (count == 4) {
    printf("ok\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x15(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <memset@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c6 <main+0x56>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11ff <main+0x8f>
lea    0xe22(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    1204 <main+0x94>
movl   $0x3,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     12a8 <main+0x138>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    124c <main+0xdc>
lea    0xdda(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    1251 <main+0xe1>
mov    -0x20(%rbp),%edi
movslq -0x24(%rbp),%rax
lea    -0x15(%rbp),%rsi
add    %rax,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x28(%rbp)
movslq -0x28(%rbp),%rax
cmp    $0x1,%rax
je     1290 <main+0x120>
lea    0xd9c(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    1295 <main+0x125>
jmp    129a <main+0x12a>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    120b <main+0x9b>
movsbl -0x15(%rbp),%eax
cmp    $0x62,%eax
jne    12be <main+0x14e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x14(%rbp),%eax
cmp    $0x61,%eax
jne    12d4 <main+0x164>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x13(%rbp),%eax
cmp    $0x64,%eax
jne    12ea <main+0x17a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x12(%rbp),%eax
cmp    $0x21,%eax
jne    1300 <main+0x190>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jne    1318 <main+0x1a8>
lea    0xd11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
movb   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
cmp    $0x2,%edi
jne    12bd <main+0x14d>
mov    0x8(%rsi),%rdi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     12d8 <main+0x168>
mov    %eax,%ebx
mov    0x2e2b(%rip),%r14
mov    (%r14),%edx
mov    %eax,%edi
mov    $0x3,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
je     12ab <main+0x13b>
lea    0x3(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x1,%eax
jne    12b4 <main+0x144>
mov    (%r14),%edx
mov    %ebx,%edi
mov    $0x2,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
je     12ab <main+0x13b>
lea    0x2(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x1,%eax
jne    12b4 <main+0x144>
mov    (%r14),%edx
mov    %ebx,%edi
mov    $0x1,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
je     12ab <main+0x13b>
lea    0x1(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x1,%eax
jne    12b4 <main+0x144>
mov    (%r14),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
je     12ab <main+0x13b>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x1,%eax
jne    12b4 <main+0x144>
xor    %eax,%eax
cmpb   $0x62,(%rsp)
sete   %al
lea    0x1(%rax),%ecx
cmpb   $0x61,0x1(%rsp)
cmovne %eax,%ecx
xor    %eax,%eax
cmpb   $0x64,0x2(%rsp)
sete   %al
add    %ecx,%eax
xor    %ecx,%ecx
cmpb   $0x21,0x3(%rsp)
sete   %cl
add    %eax,%ecx
cmp    $0x4,%ecx
jne    12a1 <main+0x131>
lea    0xd86(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd65(%rip),%rdi
jmp    12df <main+0x16f>
lea    0xd62(%rip),%rdi
jmp    12df <main+0x16f>
mov    (%rsi),%rsi
lea    0xd39(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    0xd33(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@SEEK_SET = global i32 0
@.str.2 = [6 x i8] c"lseek\00"
@.str.3 = [5 x i8] c"read\00"
@str = [3 x i8] c"ok\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = load i32, i32* @SEEK_SET
%18 = tail call i32 @lseek(i32 %14, i32 3, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %63, label %66
20: ; preds = %10
%21 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @exit(i32 -1)
unreachable
23: ; preds = %66
%24 = load i32, i32* @SEEK_SET
%25 = tail call i32 @lseek(i32 %14, i32 2, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %63, label %27
27: ; preds = %23
%28 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 2
%29 = call i32 @read(i32 %14, i8* %28, i32 1)
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %70
31: ; preds = %27
%32 = load i32, i32* @SEEK_SET
%33 = tail call i32 @lseek(i32 %14, i32 1, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %63, label %35
35: ; preds = %31
%36 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 1
%37 = call i32 @read(i32 %14, i8* %36, i32 1)
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %70
39: ; preds = %35
%40 = load i32, i32* @SEEK_SET
%41 = tail call i32 @lseek(i32 %14, i32 0, i32 %40)
%42 = icmp eq i32 %41, -1
br i1 %42, label %63, label %43
43: ; preds = %39
%44 = call i32 @read(i32 %14, i8* %4, i32 1)
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %70
46: ; preds = %43
%47 = load i8, i8* %4
%48 = icmp eq i8 %47, 98
%49 = zext i1 %48 to i32
%50 = load i8, i8* %36
%51 = icmp eq i8 %50, 97
%52 = select i1 %48, i32 2, i32 1
%53 = select i1 %51, i32 %52, i32 %49
%54 = load i8, i8* %28
%55 = icmp eq i8 %54, 100
%56 = zext i1 %55 to i32
%57 = add nuw nsw i32 %53, %56
%58 = load i8, i8* %67
%59 = icmp eq i8 %58, 33
%60 = zext i1 %59 to i32
%61 = add nuw nsw i32 %57, %60
%62 = icmp eq i32 %61, 4
br i1 %62, label %73, label %75
63: ; preds = %39, %31, %23, %16
%64 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%65 = tail call i32 @exit(i32 -1)
unreachable
66: ; preds = %16
%67 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 3
%68 = call i32 @read(i32 %14, i8* %67, i32 1)
%69 = icmp eq i32 %68, 1
br i1 %69, label %23, label %70
70: ; preds = %43, %35, %27, %66
%71 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%72 = tail call i32 @exit(i32 -1)
unreachable
73: ; preds = %46
%74 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %75
75: ; preds = %73, %46
ret i32 0
}