callsys(f, v) char f[], *v[];
{
  int t, status;
  if ((t = fork()) == 0) {
    execv(f, v);
    printf("Can't find %s\n", f);
    exit(1);
  } else if (t == -1) {
    printf("Try again\n");
    return (1);
  }
  while (t != wait(&status))
    ;
  if ((t = (status & 0377)) != 0 && t != 14) {
    if (t != 2)
      printf("Fatal error in %s\n", f);
    dexit();
  }
  return ((status >> 8) & 0377);
}


x86 assembly (clang, -O0):
<callsys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    11ae <callsys+0x4e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1070 <execv@plt>
mov    -0x10(%rbp),%rsi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11d2 <callsys+0x72>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124e <callsys+0xee>
jmp    11d7 <callsys+0x77>
jmp    11dc <callsys+0x7c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1060 <wait@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
je     11ff <callsys+0x9f>
jmp    11dc <callsys+0x7c>
mov    -0x20(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1240 <callsys+0xe0>
cmpl   $0xe,-0x1c(%rbp)
je     1240 <callsys+0xe0>
cmpl   $0x2,-0x1c(%rbp)
je     1239 <callsys+0xd9>
mov    -0x10(%rbp),%rsi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <dexit@plt>
mov    -0x20(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<callsys>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11df <callsys+0x6f>
mov    %eax,%ebp
test   %eax,%eax
je     11f9 <callsys+0x89>
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <wait@plt>
cmp    %eax,%ebp
jne    11a0 <callsys+0x30>
mov    0xc(%rsp),%eax
test   %al,%al
je     11da <callsys+0x6a>
cmp    $0x2,%al
je     11cf <callsys+0x5f>
cmp    $0xe,%al
je     11da <callsys+0x6a>
lea    0xe4a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <dexit@plt>
mov    0xc(%rsp),%eax
movzbl %ah,%eax
jmp    11f0 <callsys+0x80>
lea    0xe3c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <execv@plt>
lea    0xdf3(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"Can't find %s\0A\00"
@.str.1 = [11 x i8] c"Try again\0A\00"
@.str.2 = [19 x i8] c"Fatal error in %s\0A\00"
define i32 @callsys(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%8 = call i32 (...) @fork()
store i32 %8, i32* %6
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i8**, i8*** %5
%13 = call i32 (i8*, i8**, ...) bitcast (i32 (...)* @execv to i32 (i8*, i8**, ...)*)(i8* %11, i8** %12)
%14 = load i8*, i8** %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %14)
unreachable
16: ; preds = %2
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %47
21: ; preds = %16
br label %22
22: ; preds = %21
br label %23
23: ; preds = %27, %22
%24 = load i32, i32* %6
%25 = call i32 (i32*, ...) bitcast (i32 (...)* @wait to i32 (i32*, ...)*)(i32* %7)
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23
br label %23
28: ; preds = %23
%29 = load i32, i32* %7
%30 = and i32 %29, 255
store i32 %30, i32* %6
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %43
32: ; preds = %28
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 14
br i1 %34, label %35, label %43
35: ; preds = %32
%36 = load i32, i32* %6
%37 = icmp ne i32 %36, 2
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i8*, i8** %4
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %38, %35
%42 = call i32 (...) @dexit()
br label %43
43: ; preds = %41, %32, %28
%44 = load i32, i32* %7
%45 = ashr i32 %44, 8
%46 = and i32 %45, 255
store i32 %46, i32* %3
br label %47
47: ; preds = %43, %19
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [15 x i8] c"Can't find %s\0A\00"
@.str.2 = [19 x i8] c"Fatal error in %s\0A\00"
@str = [10 x i8] c"Try again\00"
define i32 @callsys(i8* %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 (...) @fork()
switch i32 %5, label %11 [
i32 0, label %6
i32 -1, label %9
]
6: ; preds = %2
%7 = tail call i32 (i8*, i8**, ...) bitcast (i32 (...)* @execv to i32 (i8*, i8**, ...)*)(i8* %0, i8** %1)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
tail call void @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %26
11: ; preds = %2, %11
%12 = call i32 (i32*, ...) bitcast (i32 (...)* @wait to i32 (i32*, ...)*)(i32* %3)
%13 = icmp eq i32 %5, %12
br i1 %13, label %14, label %11
14: ; preds = %11
%15 = load i32, i32* %3
%16 = trunc i32 %15 to i8
switch i8 %16, label %17 [
i8 14, label %22
i8 0, label %22
i8 2, label %19
]
17: ; preds = %14
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %19
19: ; preds = %14, %17
%20 = call i32 (...) @dexit()
%21 = load i32, i32* %3
br label %22
22: ; preds = %14, %14, %19
%23 = phi i32 [ %15, %14 ], [ %15, %14 ], [ %21, %19 ]
%24 = lshr i32 %23, 8
%25 = and i32 %24, 255
br label %26
26: ; preds = %22, %9
%27 = phi i32 [ 1, %9 ], [ %25, %22 ]
ret i32 %27
}