#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*/ bsearch(int, char *);
int close(int);
int /*<<< orphan*/ err_exit(char *, char *);
int /*<<< orphan*/ err_msg(char *, char *);
int /*<<< orphan*/ err_sys(char *);
int open(char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd;
  if (argc != 3) {
    err_msg("Usage: %s string file", argv[0]);
    return 0;
  }
  if ((fd = open(argv[2], O_RDONLY)) == -1)
    err_exit("failed to open %s", argv[2]);
  bsearch(fd, argv[1]);
  if (close(fd) == -1)
    err_sys("close");
  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)
cmpl   $0x3,-0x8(%rbp)
je     119f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
call   1070 <err_msg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1209 <main+0xa9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11d5 <main+0x75>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe46(%rip),%rdi
call   1050 <err_exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1080 <bsearch@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    1202 <main+0xa2>
lea    0xe2b(%rip),%rdi
call   1030 <err_sys@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11b9 <main+0x59>
mov    0x10(%rbx),%rdi
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1194 <main+0x34>
mov    0x10(%rbx),%rsi
lea    0xe87(%rip),%rdi
call   1050 <err_exit@plt>
mov    0x8(%rbx),%rsi
mov    %ebp,%edi
call   1080 <bsearch@plt>
mov    %ebp,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    11c8 <main+0x68>
lea    0xe76(%rip),%rdi
call   1030 <err_sys@plt>
jmp    11c8 <main+0x68>
mov    (%rbx),%rsi
lea    0xe3d(%rip),%rdi
call   1070 <err_msg@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Usage: %s string file\00"
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"failed to open %s\00"
@.str.2 = [6 x i8] c"close\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 3
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @err_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 0, i32* %3
br label %38
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %6
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %26
21: ; preds = %14
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @err_exit(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %21, %14
%27 = load i32, i32* %6
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @bsearch(i32 %27, i8* %30)
%32 = load i32, i32* %6
%33 = call i32 @close(i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %26
%36 = call i32 @err_sys(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %26
store i32 0, i32* %3
br label %38
38: ; preds = %37, %9
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [22 x i8] c"Usage: %s string file\00"
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"failed to open %s\00"
@.str.2 = [6 x i8] c"close\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @err_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %24
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = load i8*, i8** %8
%15 = tail call i32 @err_exit(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %7
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @bsearch(i32 %11, i8* %18)
%20 = tail call i32 @close(i32 %11)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = tail call i32 @err_sys(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %16, %22, %4
ret i32 0
}