callsys(f, v) char f[], *v[];
{
  int t, status, i;
  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) {
    if (t != 2) {
      printf("Fatal error in %s\n", f);
      printf("t = %d\n", t);
    }
    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    1255 <callsys+0xf5>
jmp    11d7 <callsys+0x77>
jmp    11dc <callsys+0x7c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1060 <wait@plt>
mov    %eax,%ecx
mov    -0x28(%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     1247 <callsys+0xe7>
cmpl   $0x2,-0x1c(%rbp)
je     1240 <callsys+0xe0>
mov    -0x10(%rbp),%rsi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xdf4(%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     11ee <callsys+0x7e>
mov    %eax,%ebp
test   %eax,%eax
je     1208 <callsys+0x98>
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     11e9 <callsys+0x79>
cmp    $0x2,%al
je     11de <callsys+0x6e>
movzbl %al,%ebx
lea    0xe4b(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe4d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <dexit@plt>
mov    0xc(%rsp),%eax
movzbl %ah,%eax
jmp    11ff <callsys+0x8f>
lea    0xe35(%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    0xde4(%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"
@.str.3 = [8 x i8] c"t = %d\0A\00"
define i32 @callsys(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%9 = call i32 (...) @fork()
store i32 %9, i32* %6
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i8**, i8*** %5
%14 = call i32 (i8*, i8**, ...) bitcast (i32 (...)* @execv to i32 (i8*, i8**, ...)*)(i8* %12, i8** %13)
%15 = load i8*, i8** %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %15)
unreachable
17: ; preds = %2
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = 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
22: ; preds = %17
br label %23
23: ; preds = %22
br label %24
24: ; preds = %28, %23
%25 = load i32, i32* %6
%26 = call i32 (i32*, ...) bitcast (i32 (...)* @wait to i32 (i32*, ...)*)(i32* %7)
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
br label %24
29: ; preds = %24
%30 = load i32, i32* %7
%31 = and i32 %30, 255
store i32 %31, i32* %6
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %43
33: ; preds = %29
%34 = load i32, i32* %6
%35 = icmp ne i32 %34, 2
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i8*, i8** %4
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = load i32, i32* %6
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %36, %33
%42 = call i32 (...) @dexit()
br label %43
43: ; preds = %41, %29
%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, %20
%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.3 = [8 x i8] c"t = %d\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 %28
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 0, label %24
i8 2, label %21
]
17: ; preds = %14
%18 = and i32 %15, 255
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %21
21: ; preds = %14, %17
%22 = call i32 (...) @dexit()
%23 = load i32, i32* %3
br label %24
24: ; preds = %14, %21
%25 = phi i32 [ %15, %14 ], [ %23, %21 ]
%26 = lshr i32 %25, 8
%27 = and i32 %26, 255
br label %28
28: ; preds = %24, %9
%29 = phi i32 [ 1, %9 ], [ %27, %24 ]
ret i32 %29
}