#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  char data[10];
  int fd, size;
  if (argc != 2) {
    fprintf(stderr, "Incorrect number of arguments, got %i\n", argc);
    return 1;
  }
  fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "First argument is wrong.\n");
    return 1;
  }
  size = read(fd, data, 8);
  if (size < 0) {
    fprintf(stderr, "Failed to read: %s\n", strerror(errno));
    return 1;
  }
  if (strncmp(data, "contents", 8) != 0) {
    fprintf(stderr, "Contents don't match, got %s\n", data);
    return 1;
  }
  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)
cmpl   $0x2,-0x8(%rbp)
je     1196 <main+0x46>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1281 <main+0x131>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11dc <main+0x8c>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1281 <main+0x131>
mov    -0x20(%rbp),%edi
lea    -0x1a(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1234 <main+0xe4>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1281 <main+0x131>
lea    -0x1a(%rbp),%rdi
lea    0xe16(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     127a <main+0x12a>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
lea    -0x1a(%rbp),%rdx
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1281 <main+0x131>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11bb <main+0x6b>
mov    0x8(%rsi),%rdi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11d6 <main+0x86>
lea    0x6(%rsp),%rsi
mov    %eax,%edi
mov    $0x8,%edx
call   1040 <read@plt>
test   %eax,%eax
js     11ef <main+0x9f>
lea    0xec9(%rip),%rsi
lea    0x6(%rsp),%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1224 <main+0xd4>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xeaa(%rip),%rsi
lea    0x6(%rsp),%rdx
jmp    1212 <main+0xc2>
mov    %edi,%edx
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1219 <main+0xc9>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1219 <main+0xc9>
mov    0x2de2(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe34(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
jmp    121e <main+0xce>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"Incorrect number of arguments, got %i\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"First argument is wrong.\0A\00"
@.str.2 = [20 x i8] c"Failed to read: %s\0A\00"
@errno = global i32 0
@.str.3 = [9 x i8] c"contents\00"
@.str.4 = [30 x i8] c"Contents don't match, got %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i8]
%7 = alloca i32
%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 ne i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i32, i32* %4
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 1, i32* %3
br label %46
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %46
26: ; preds = %15
%27 = load i32, i32* %7
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%29 = call i32 @read(i32 %27, i8* %28, i32 8)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %26
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %35)
store i32 1, i32* %3
br label %46
37: ; preds = %26
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%39 = call i64 @strncmp(i8* %38, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %43)
store i32 1, i32* %3
br label %46
45: ; preds = %37
store i32 0, i32* %3
br label %46
46: ; preds = %45, %41, %32, %23, %11
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"Incorrect number of arguments, got %i\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"First argument is wrong.\0A\00"
@.str.2 = [20 x i8] c"Failed to read: %s\0A\00"
@errno = global i32 0
@.str.3 = [9 x i8] c"contents\00"
@.str.4 = [30 x i8] c"Contents don't match, got %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %32
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %32
18: ; preds = %9
%19 = call i32 @read(i32 %13, i8* %4, i32 8)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = tail call i8* @strerror(i32 %23)
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %32
26: ; preds = %18
%27 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %32
32: ; preds = %26, %29, %21, %15, %6
%33 = phi i32 [ 1, %6 ], [ 1, %15 ], [ 1, %21 ], [ 1, %29 ], [ 0, %26 ]
ret i32 %33
}