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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ shift(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char *argv[]) {
  char buffer[5] = {0};
  char buffer2[5] = {0};
  int fd;
  if (argc != 2) {
    printf("Usage: %s <file>\n", argv[0]);
    exit(-1);
  }
  if ((fd = open(argv[1], O_RDONLY)) == -1) {
    do {
      perror("open");
      exit(-1);
    } while (0);
    ;
  }
  if (read(fd, buffer, 4) != 4) {
    do {
      perror("read");
      exit(-1);
    } while (0);
    ;
  }
  memcpy(buffer2, buffer, sizeof(buffer2));
  shift(buffer, buffer2);
  if (strncmp(buffer, "bad!", 4) == 0) {
    printf("ok\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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>
lea    -0x1a(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
je     11ef <main+0x5f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    122c <main+0x9c>
jmp    1216 <main+0x86>
lea    0xdf5(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
cmp    $0x4,%eax
je     1261 <main+0xd1>
jmp    124b <main+0xbb>
lea    0xdc5(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
lea    -0x1a(%rbp),%rdi
lea    -0x15(%rbp),%rsi
mov    $0x5,%edx
call   1070 <memcpy@plt>
lea    -0x15(%rbp),%rdi
lea    -0x1a(%rbp),%rsi
call   1080 <shift@plt>
lea    -0x15(%rbp),%rdi
lea    0xd91(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12ad <main+0x11d>
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movb   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movb   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
cmp    $0x2,%edi
jne    123f <main+0xaf>
mov    0x8(%rsi),%rdi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     125a <main+0xca>
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1060 <read@plt>
cmp    $0x4,%eax
jne    1263 <main+0xd3>
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
call   1070 <memcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <shift@plt>
lea    0xe05(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1235 <main+0xa5>
lea    0xdf1(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    (%rsi),%rsi
lea    0xdb7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
lea    0xdb1(%rip),%rdi
jmp    126a <main+0xda>
lea    0xdad(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <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"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [5 x i8] c"bad!\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 [5 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [5 x i8]* %6 to i8*
%10 = bitcast [5 x i8]* %7 to i8*
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %8
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %19
br label %27
27: ; preds = %26
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; No predecessors!
br label %31
31: ; preds = %30, %19
%32 = load i32, i32* %8
%33 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 4)
%35 = icmp ne i32 %34, 4
br i1 %35, label %36, label %41
36: ; preds = %31
br label %37
37: ; preds = %36
%38 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; No predecessors!
br label %41
41: ; preds = %40, %31
%42 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%43 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%44 = call i32 @memcpy(i8* %42, i8* %43, i32 5)
%45 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%46 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%47 = call i32 @shift(i8* %45, i8* %46)
%48 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%49 = call i64 @strncmp(i8* %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %41
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %51, %41
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"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [5 x i8] c"bad!\00"
@str = [3 x i8] c"ok\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [5 x i8]
%4 = alloca [5 x i8]
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 @open(i8* %14, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 -1)
unreachable
21: ; preds = %12
%22 = call i32 @read(i32 %16, i8* %5, i32 4)
%23 = icmp eq i32 %22, 4
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i32 @exit(i32 -1)
unreachable
27: ; preds = %21
%28 = call i32 @memcpy(i8* %6, i8* %5, i32 5)
%29 = call i32 @shift(i8* %5, i8* %6)
%30 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
ret i32 0
}