#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*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sed(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int fd, i;
  char *option;
  if (argc <= 1) {
    fprintf(stderr, "usage: sed [OPTION] [input]\n");
    fprintf(stderr, "OPTION: [line][command]\n");
    fprintf(stderr,
            "command: d(delete), s(substitute), a(append), i(insert)\n");
    exit(1);
  }
  option = argv[1];
  if (argc <= 2) {
    sed(option, 0);
    exit(0);
  }
  for (i = 2; i < argc; i++) {
    if ((fd = open(argv[i], 0)) < 0) {
      fprintf(stderr, "sed: cannot open %s\n", argv[i]);
      exit(1);
    }
    sed(option, fd);
    close(fd);
  }
  exit(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   $0x1,-0x8(%rbp)
jg     11bf <main+0x6f>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jg     11e7 <main+0x97>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1070 <sed@plt>
xor    %edi,%edi
call   1060 <exit@plt>
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1268 <main+0x118>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %esi,%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1246 <main+0xf6>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <sed@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ee <main+0x9e>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x1,%edi
jg     119e <main+0x4e>
mov    0x2e7c(%rip),%rbx
mov    (%rbx),%edi
lea    0xe93(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xea0(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xea9(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    %rsi,%r14
mov    0x8(%rsi),%r15
cmp    $0x2,%edi
jne    11bb <main+0x6b>
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <sed@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    %edi,%r12d
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14,%rbx,8),%rdi
xor    %esi,%esi
call   1050 <open@plt>
test   %eax,%eax
js     1202 <main+0xb2>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %eax,%esi
call   1070 <sed@plt>
mov    %ebp,%edi
call   1030 <close@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11d0 <main+0x80>
xor    %edi,%edi
call   1060 <exit@plt>
mov    %ebx,%eax
mov    0x2dd5(%rip),%rcx
mov    (%rcx),%edi
mov    (%r14,%rax,8),%rdx
lea    0xe57(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"usage: sed [OPTION] [input]\0A\00"
@.str.1 = [25 x i8] c"OPTION: [line][command]\0A\00"
@.str.2 = [57 x i8] c"command: d(delete), s(substitute), a(append), i(insert)\0A\00"
@.str.3 = [21 x i8] c"sed: cannot open %s\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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 1
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0))
%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
store i8* %22, i8** %8
%23 = load i32, i32* %4
%24 = icmp sle i32 %23, 2
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = load i8*, i8** %8
%27 = call i32 @sed(i8* %26, i32 0)
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %19
store i32 2, i32* %7
br label %30
30: ; preds = %57, %29
%31 = load i32, i32* %7
%32 = load i32, i32* %4
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %60
34: ; preds = %30
%35 = load i8**, i8*** %5
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = call i32 @open(i8* %39, i32 0)
store i32 %40, i32* %6
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %51
42: ; preds = %34
%43 = load i32, i32* @stderr
%44 = load i8**, i8*** %5
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %34
%52 = load i8*, i8** %8
%53 = load i32, i32* %6
%54 = call i32 @sed(i8* %52, i32 %53)
%55 = load i32, i32* %6
%56 = call i32 @close(i32 %55)
br label %57
57: ; preds = %51
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %30
60: ; preds = %30
%61 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"usage: sed [OPTION] [input]\0A\00"
@.str.1 = [25 x i8] c"OPTION: [line][command]\0A\00"
@.str.2 = [57 x i8] c"command: d(delete), s(substitute), a(append), i(insert)\0A\00"
@.str.3 = [21 x i8] c"sed: cannot open %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0))
%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 = icmp eq i32 %0, 2
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = zext i32 %0 to i64
br label %21
18: ; preds = %12
%19 = tail call i32 @sed(i8* %14, i32 0)
%20 = tail call i32 @exit(i32 0)
unreachable
21: ; preds = %16, %34
%22 = phi i64 [ 2, %16 ], [ %37, %34 ]
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = tail call i32 @open(i8* %24, i32 0)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %21
%28 = and i64 %22, 4294967295
%29 = getelementptr inbounds i8*, i8** %1, i64 %28
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %29
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %21
%35 = tail call i32 @sed(i8* %14, i32 %25)
%36 = tail call i32 @close(i32 %25)
%37 = add nuw nsw i64 %22, 1
%38 = icmp eq i64 %37, %17
br i1 %38, label %39, label %21
39: ; preds = %34
%40 = tail call i32 @exit(i32 0)
unreachable
}