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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fatal_error(int, char *, int /*<<< orphan*/);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int getchar();
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char const *, char *);
void do_cmd(int argc, char **argv) {
  const char *s;
  s = argv[1];
  if (strcmp(s, "exit") == 0)
    exit(0);
  else if (strcmp(s, "echo") == 0) {
    int i;
    for (i = 2; i < argc; ++i) {
      if (i > 2)
        putchar(' ');
      fputs(argv[i], stdout);
    }
    putchar('\n');
    exit(0);
  } else if (strcmp(s, "echoerr") == 0) {
    int i;
    for (i = 2; i < argc; ++i) {
      if (i > 3)
        putc(' ', (i & 1) == 0 ? stdout : stderr);
      fputs(argv[i], (i & 1) == 0 ? stdout : stderr);
    }
    putc('\n', stdout);
    putc('\n', stderr);
    exit(0);
  } else if (strcmp(s, "error") == 0)
    exit(1);
  else if (strcmp(s, "abort") == 0)
    abort();
  else if (strcmp(s, "copy") == 0) {
    int c;
    while ((c = getchar()) != EOF)
      putchar(c);
    exit(0);
  } else if (strcmp(s, "write") == 0) {
    FILE *e;
    int c;
    e = fopen(argv[2], "w");
    if (e == NULL)
      fatal_error(506, "fopen for write failed", errno);
    while ((c = getchar()) != EOF)
      putc(c, e);
    if (fclose(e) != 0)
      fatal_error(510, "fclose for write failed", errno);
    exit(0);
  } else {
    char buf[1000];
    snprintf(buf, sizeof buf, "unrecognized command %s", argv[1]);
    fatal_error(518, buf, 0);
  }
  exit(1);
}


x86 assembly (clang, -O0):
<do_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    11ef <do_cmd+0x3f>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    126a <do_cmd+0xba>
movl   $0x2,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1259 <do_cmd+0xa9>
cmpl   $0x2,-0x1c(%rbp)
jle    1230 <do_cmd+0x80>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d85(%rip),%rax
mov    (%rax),%rsi
call   1070 <fputs@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1210 <do_cmd+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xd95(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1381 <do_cmd+0x1d1>
movl   $0x2,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1352 <do_cmd+0x1a2>
cmpl   $0x3,-0x20(%rbp)
jle    12e8 <do_cmd+0x138>
mov    -0x20(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    12c6 <do_cmd+0x116>
mov    0x2d11(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x428(%rbp)
jmp    12d7 <do_cmd+0x127>
mov    0x2d0b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rsi
mov    $0x20,%edi
call   1090 <putc@plt>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x430(%rbp)
mov    -0x20(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1320 <do_cmd+0x170>
mov    0x2cb7(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x438(%rbp)
jmp    1331 <do_cmd+0x181>
mov    0x2cb1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x438(%rbp)
mov    -0x430(%rbp),%rdi
mov    -0x438(%rbp),%rsi
call   1070 <fputs@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    128b <do_cmd+0xdb>
mov    0x2c6f(%rip),%rax
mov    (%rax),%rsi
mov    $0xa,%edi
call   1090 <putc@plt>
mov    0x2c6b(%rip),%rax
mov    (%rax),%rsi
mov    $0xa,%edi
call   1090 <putc@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xc86(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    13a5 <do_cmd+0x1f5>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xc68(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    13c6 <do_cmd+0x216>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x18(%rbp),%rdi
lea    0xc4d(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1412 <do_cmd+0x262>
jmp    13e5 <do_cmd+0x235>
mov    $0x0,%al
call   10a0 <getchar@plt>
mov    %eax,-0x24(%rbp)
mov    0x2bf2(%rip),%rcx
cmp    (%rcx),%eax
je     140b <do_cmd+0x25b>
mov    -0x24(%rbp),%edi
call   1030 <putchar@plt>
jmp    13e5 <do_cmd+0x235>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xc06(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    14cc <do_cmd+0x31c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xbee(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1469 <do_cmd+0x2b9>
mov    0x2b7a(%rip),%rax
mov    (%rax),%edx
mov    $0x1fa,%edi
lea    0xbc7(%rip),%rsi
call   10b0 <fatal_error@plt>
jmp    146e <do_cmd+0x2be>
mov    $0x0,%al
call   10a0 <getchar@plt>
mov    %eax,-0x34(%rbp)
mov    0x2b69(%rip),%rcx
cmp    (%rcx),%eax
je     1498 <do_cmd+0x2e8>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1090 <putc@plt>
jmp    146e <do_cmd+0x2be>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     14c5 <do_cmd+0x315>
mov    0x2b1e(%rip),%rax
mov    (%rax),%edx
mov    $0x1fe,%edi
lea    0xb82(%rip),%rsi
call   10b0 <fatal_error@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x3e8,%esi
lea    0xb73(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x420(%rbp),%rsi
mov    $0x206,%edi
xor    %edx,%edx
call   10b0 <fatal_error@plt>
jmp    1504 <do_cmd+0x354>
jmp    1509 <do_cmd+0x359>
jmp    150e <do_cmd+0x35e>
jmp    1513 <do_cmd+0x363>
jmp    1518 <do_cmd+0x368>
jmp    151d <do_cmd+0x36d>
mov    $0x1,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<do_cmd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3e8,%rsp
mov    %rsi,%r13
mov    %edi,%r14d
mov    0x8(%rsi),%rbp
lea    0xe2e(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    11e6 <do_cmd+0x36>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xe18(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1261 <do_cmd+0xb1>
cmp    $0x3,%r14d
jl     1250 <do_cmd+0xa0>
mov    0x10(%r13),%rdi
mov    0x2dbd(%rip),%r15
mov    (%r15),%rsi
call   1070 <fputs@plt>
cmp    $0x3,%r14d
je     1250 <do_cmd+0xa0>
mov    %r14d,%ebx
mov    $0x3,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    0x0(%r13,%rbp,8),%rdi
mov    (%r15),%rsi
call   1070 <fputs@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1230 <do_cmd+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xda2(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    12e1 <do_cmd+0x131>
cmp    $0x3,%r14d
jl     12b2 <do_cmd+0x102>
mov    0x10(%r13),%rdi
mov    0x2d42(%rip),%r15
mov    (%r15),%rsi
call   1070 <fputs@plt>
cmp    $0x3,%r14d
je     12b2 <do_cmd+0x102>
mov    0x18(%r13),%rdi
mov    0x2d39(%rip),%r12
mov    (%r12),%rsi
call   1070 <fputs@plt>
cmp    $0x4,%r14d
jne    1367 <do_cmd+0x1b7>
mov    0x2d0f(%rip),%rax
mov    (%rax),%rsi
mov    $0xa,%edi
call   1090 <putc@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%rsi
mov    $0xa,%edi
call   1090 <putc@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xd2a(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    12ff <do_cmd+0x14f>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd12(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    131a <do_cmd+0x16a>
xor    %eax,%eax
call   1040 <abort@plt>
lea    0xcfd(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    13b5 <do_cmd+0x205>
xor    %eax,%eax
call   10a0 <getchar@plt>
mov    0x2ca8(%rip),%rbx
cmp    (%rbx),%eax
je     11df <do_cmd+0x2f>
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   10a0 <getchar@plt>
cmp    (%rbx),%eax
jne    1350 <do_cmd+0x1a0>
jmp    11df <do_cmd+0x2f>
mov    %r14d,%r14d
mov    $0x4,%ebp
jmp    13a7 <do_cmd+0x1f7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rsi
mov    $0x20,%edi
call   1090 <putc@plt>
mov    0x0(%r13,%rbp,8),%rdi
mov    (%rbx),%rsi
call   1070 <fputs@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
je     12b2 <do_cmd+0x102>
mov    %r12,%rbx
test   $0x1,%bpl
jne    1380 <do_cmd+0x1d0>
mov    %r15,%rbx
jmp    1380 <do_cmd+0x1d0>
lea    0xc67(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    1468 <do_cmd+0x2b8>
mov    0x10(%r13),%rdi
lea    0xc51(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    13ff <do_cmd+0x24f>
mov    0x2be4(%rip),%rax
mov    (%rax),%edx
lea    0xc36(%rip),%rsi
mov    $0x1fa,%edi
call   10b0 <fatal_error@plt>
xor    %eax,%eax
call   10a0 <getchar@plt>
mov    0x2bdb(%rip),%rbp
cmp    0x0(%rbp),%eax
je     1436 <do_cmd+0x286>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%edi
mov    %rbx,%rsi
call   1090 <putc@plt>
xor    %eax,%eax
call   10a0 <getchar@plt>
cmp    0x0(%rbp),%eax
jne    1420 <do_cmd+0x270>
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
je     11df <do_cmd+0x2f>
mov    0x2b82(%rip),%rax
mov    (%rax),%edx
lea    0xbeb(%rip),%rsi
mov    $0x1fe,%edi
call   10b0 <fatal_error@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    0x8(%r13),%rcx
lea    0xbe7(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1060 <snprintf@plt>
mov    $0x206,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   10b0 <fatal_error@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"exit\00"
@.str.1 = [5 x i8] c"echo\00"
@stdout = global i32* null
@.str.2 = [8 x i8] c"echoerr\00"
@stderr = global i32* null
@.str.3 = [6 x i8] c"error\00"
@.str.4 = [6 x i8] c"abort\00"
@.str.5 = [5 x i8] c"copy\00"
@EOF = global i32 0
@.str.6 = [6 x i8] c"write\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [23 x i8] c"fopen for write failed\00"
@errno = global i32 0
@.str.9 = [24 x i8] c"fclose for write failed\00"
@.str.10 = [24 x i8] c"unrecognized command %s\00"
define void @do_cmd(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca [1000 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %2
%21 = load i8*, i8** %5
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %48
24: ; preds = %20
store i32 2, i32* %6
br label %25
25: ; preds = %42, %24
%26 = load i32, i32* %6
%27 = load i32, i32* %3
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %45
29: ; preds = %25
%30 = load i32, i32* %6
%31 = icmp sgt i32 %30, 2
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @putchar(i32 32)
br label %34
34: ; preds = %32, %29
%35 = load i8**, i8*** %4
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = load i32*, i32** @stdout
%41 = call i32 @fputs(i8* %39, i32* %40)
br label %42
42: ; preds = %34
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %25
45: ; preds = %25
%46 = call i32 @putchar(i32 10)
%47 = call i32 @exit(i32 0)
unreachable
48: ; preds = %20
%49 = load i8*, i8** %5
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %96
52: ; preds = %48
store i32 2, i32* %7
br label %53
53: ; preds = %87, %52
%54 = load i32, i32* %7
%55 = load i32, i32* %3
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %90
57: ; preds = %53
%58 = load i32, i32* %7
%59 = icmp sgt i32 %58, 3
br i1 %59, label %60, label %71
60: ; preds = %57
%61 = load i32, i32* %7
%62 = and i32 %61, 1
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %60
%65 = load i32*, i32** @stdout
br label %68
66: ; preds = %60
%67 = load i32*, i32** @stderr
br label %68
68: ; preds = %66, %64
%69 = phi i32* [ %65, %64 ], [ %67, %66 ]
%70 = call i32 @putc(i32 32, i32* %69)
br label %71
71: ; preds = %68, %57
%72 = load i8**, i8*** %4
%73 = load i32, i32* %7
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8*, i8** %72, i64 %74
%76 = load i8*, i8** %75
%77 = load i32, i32* %7
%78 = and i32 %77, 1
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %71
%81 = load i32*, i32** @stdout
br label %84
82: ; preds = %71
%83 = load i32*, i32** @stderr
br label %84
84: ; preds = %82, %80
%85 = phi i32* [ %81, %80 ], [ %83, %82 ]
%86 = call i32 @fputs(i8* %76, i32* %85)
br label %87
87: ; preds = %84
%88 = load i32, i32* %7
%89 = add nsw i32 %88, 1
store i32 %89, i32* %7
br label %53
90: ; preds = %53
%91 = load i32*, i32** @stdout
%92 = call i32 @putc(i32 10, i32* %91)
%93 = load i32*, i32** @stderr
%94 = call i32 @putc(i32 10, i32* %93)
%95 = call i32 @exit(i32 0)
unreachable
96: ; preds = %48
%97 = load i8*, i8** %5
%98 = call i64 @strcmp(i8* %97, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%99 = icmp eq i64 %98, 0
br i1 %99, label %100, label %102
100: ; preds = %96
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %96
%103 = load i8*, i8** %5
%104 = call i64 @strcmp(i8* %103, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%105 = icmp eq i64 %104, 0
br i1 %105, label %106, label %108
106: ; preds = %102
%107 = call i32 (...) @abort()
unreachable
108: ; preds = %102
%109 = load i8*, i8** %5
%110 = call i64 @strcmp(i8* %109, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%111 = icmp eq i64 %110, 0
br i1 %111, label %112, label %122
112: ; preds = %108
br label %113
113: ; preds = %117, %112
%114 = call i32 (...) @getchar()
store i32 %114, i32* %8
%115 = load i32, i32* @EOF
%116 = icmp ne i32 %114, %115
br i1 %116, label %117, label %120
117: ; preds = %113
%118 = load i32, i32* %8
%119 = call i32 @putchar(i32 %118)
br label %113
120: ; preds = %113
%121 = call i32 @exit(i32 0)
unreachable
122: ; preds = %108
%123 = load i8*, i8** %5
%124 = call i64 @strcmp(i8* %123, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%125 = icmp eq i64 %124, 0
br i1 %125, label %126, label %154
126: ; preds = %122
%127 = load i8**, i8*** %4
%128 = getelementptr inbounds i8*, i8** %127, i64 2
%129 = load i8*, i8** %128
%130 = call i32* @fopen(i8* %129, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %130, i32** %9
%131 = load i32*, i32** %9
%132 = icmp eq i32* %131, null
br i1 %132, label %133, label %136
133: ; preds = %126
%134 = load i32, i32* @errno
%135 = call i32 @fatal_error(i32 506, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %134)
br label %136
136: ; preds = %133, %126
br label %137
137: ; preds = %141, %136
%138 = call i32 (...) @getchar()
store i32 %138, i32* %10
%139 = load i32, i32* @EOF
%140 = icmp ne i32 %138, %139
br i1 %140, label %141, label %145
141: ; preds = %137
%142 = load i32, i32* %10
%143 = load i32*, i32** %9
%144 = call i32 @putc(i32 %142, i32* %143)
br label %137
145: ; preds = %137
%146 = load i32*, i32** %9
%147 = call i64 @fclose(i32* %146)
%148 = icmp ne i64 %147, 0
br i1 %148, label %149, label %152
149: ; preds = %145
%150 = load i32, i32* @errno
%151 = call i32 @fatal_error(i32 510, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i32 %150)
br label %152
152: ; preds = %149, %145
%153 = call i32 @exit(i32 0)
unreachable
154: ; preds = %122
%155 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%156 = load i8**, i8*** %4
%157 = getelementptr inbounds i8*, i8** %156, i64 1
%158 = load i8*, i8** %157
%159 = call i32 @snprintf(i8* %155, i32 1000, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i8* %158)
%160 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%161 = call i32 @fatal_error(i32 518, i8* %160, i32 0)
br label %162
162: ; preds = %154
br label %163
163: ; preds = %162
br label %164
164: ; preds = %163
br label %165
165: ; preds = %164
br label %166
166: ; preds = %165
br label %167
167: ; preds = %166
br label %168
168: ; preds = %167
%169 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [5 x i8] c"exit\00"
@.str.1 = [5 x i8] c"echo\00"
@stdout = global i32* null
@.str.2 = [8 x i8] c"echoerr\00"
@stderr = global i32* null
@.str.3 = [6 x i8] c"error\00"
@.str.4 = [6 x i8] c"abort\00"
@.str.5 = [5 x i8] c"copy\00"
@EOF = global i32 0
@.str.6 = [6 x i8] c"write\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [23 x i8] c"fopen for write failed\00"
@errno = global i32 0
@.str.9 = [24 x i8] c"fclose for write failed\00"
@.str.10 = [24 x i8] c"unrecognized command %s\00"
define void @do_cmd(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2
%11 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %34
13: ; preds = %10
%14 = icmp sgt i32 %0, 2
br i1 %14, label %15, label %31
15: ; preds = %13
%16 = zext i32 %0 to i64
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = load i32*, i32** @stdout
%20 = tail call i32 @fputs(i8* %18, i32* %19)
%21 = icmp eq i32 %0, 3
br i1 %21, label %31, label %22
22: ; preds = %15, %22
%23 = phi i64 [ %29, %22 ], [ 3, %15 ]
%24 = tail call i32 @putchar(i32 32)
%25 = getelementptr inbounds i8*, i8** %1, i64 %23
%26 = load i8*, i8** %25
%27 = load i32*, i32** @stdout
%28 = tail call i32 @fputs(i8* %26, i32* %27)
%29 = add nuw nsw i64 %23, 1
%30 = icmp eq i64 %29, %16
br i1 %30, label %31, label %22
31: ; preds = %22, %15, %13
%32 = tail call i32 @putchar(i32 10)
%33 = tail call i32 @exit(i32 0)
unreachable
34: ; preds = %10
%35 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %76
37: ; preds = %34
%38 = icmp sgt i32 %0, 2
br i1 %38, label %39, label %70
39: ; preds = %37
%40 = zext i32 %0 to i64
%41 = getelementptr inbounds i8*, i8** %1, i64 2
%42 = load i8*, i8** %41
%43 = load i32*, i32** @stdout
%44 = tail call i32 @fputs(i8* %42, i32* %43)
%45 = icmp eq i32 %0, 3
br i1 %45, label %70, label %46
46: ; preds = %39
%47 = getelementptr inbounds i8*, i8** %1, i64 3
%48 = load i8*, i8** %47
%49 = load i32*, i32** @stderr
%50 = tail call i32 @fputs(i8* %48, i32* %49)
%51 = icmp eq i32 %0, 4
br i1 %51, label %70, label %52
52: ; preds = %46, %52
%53 = phi i64 [ %68, %52 ], [ 4, %46 ]
%54 = trunc i64 %53 to i32
%55 = and i32 %54, 1
%56 = icmp eq i32 %55, 0
%57 = load i32*, i32** @stdout
%58 = load i32*, i32** @stderr
%59 = select i1 %56, i32* %57, i32* %58
%60 = tail call i32 @putc(i32 32, i32* %59)
%61 = getelementptr inbounds i8*, i8** %1, i64 %53
%62 = load i8*, i8** %61
%63 = icmp eq i32 %55, 0
%64 = load i32*, i32** @stdout
%65 = load i32*, i32** @stderr
%66 = select i1 %63, i32* %64, i32* %65
%67 = tail call i32 @fputs(i8* %62, i32* %66)
%68 = add nuw nsw i64 %53, 1
%69 = icmp eq i64 %68, %40
br i1 %69, label %70, label %52
70: ; preds = %52, %39, %46, %37
%71 = load i32*, i32** @stdout
%72 = tail call i32 @putc(i32 10, i32* %71)
%73 = load i32*, i32** @stderr
%74 = tail call i32 @putc(i32 10, i32* %73)
%75 = tail call i32 @exit(i32 0)
unreachable
76: ; preds = %34
%77 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %76
%80 = tail call i32 @exit(i32 1)
unreachable
81: ; preds = %76
%82 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %81
%85 = tail call i32 (...) @abort()
unreachable
86: ; preds = %81
%87 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %101
89: ; preds = %86
%90 = tail call i32 (...) @getchar()
%91 = load i32, i32* @EOF
%92 = icmp eq i32 %90, %91
br i1 %92, label %99, label %93
93: ; preds = %89, %93
%94 = phi i32 [ %96, %93 ], [ %90, %89 ]
%95 = tail call i32 @putchar(i32 %94)
%96 = tail call i32 (...) @getchar()
%97 = load i32, i32* @EOF
%98 = icmp eq i32 %96, %97
br i1 %98, label %99, label %93
99: ; preds = %93, %89
%100 = tail call i32 @exit(i32 0)
unreachable
101: ; preds = %86
%102 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%103 = icmp eq i64 %102, 0
br i1 %103, label %104, label %130
104: ; preds = %101
%105 = getelementptr inbounds i8*, i8** %1, i64 2
%106 = load i8*, i8** %105
%107 = tail call i32* @fopen(i8* %106, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%108 = icmp eq i32* %107, null
br i1 %108, label %109, label %112
109: ; preds = %104
%110 = load i32, i32* @errno
%111 = tail call i32 @fatal_error(i32 506, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %110)
br label %112
112: ; preds = %109, %104
%113 = tail call i32 (...) @getchar()
%114 = load i32, i32* @EOF
%115 = icmp eq i32 %113, %114
br i1 %115, label %122, label %116
116: ; preds = %112, %116
%117 = phi i32 [ %119, %116 ], [ %113, %112 ]
%118 = tail call i32 @putc(i32 %117, i32* %107)
%119 = tail call i32 (...) @getchar()
%120 = load i32, i32* @EOF
%121 = icmp eq i32 %119, %120
br i1 %121, label %122, label %116
122: ; preds = %116, %112
%123 = tail call i64 @fclose(i32* %107)
%124 = icmp eq i64 %123, 0
br i1 %124, label %128, label %125
125: ; preds = %122
%126 = load i32, i32* @errno
%127 = tail call i32 @fatal_error(i32 510, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i32 %126)
br label %128
128: ; preds = %125, %122
%129 = tail call i32 @exit(i32 0)
unreachable
130: ; preds = %101
%131 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%132 = load i8*, i8** %4
%133 = call i32 @snprintf(i8* %131, i32 1000, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i8* %132)
%134 = call i32 @fatal_error(i32 518, i8* %131, i32 0)
%135 = call i32 @exit(i32 1)
unreachable
}