callsys(f, v) char f[], *v[];
{
  int t, status, i;
  if ((t = fork()) == 0) {
    for (i = 1; i <= 12; i++)
      signal(i, 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   1090 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    11e9 <callsys+0x79>
movl   $0x1,-0x24(%rbp)
cmpl   $0xc,-0x24(%rbp)
jg     11be <callsys+0x4e>
mov    -0x24(%rbp),%edi
xor    %esi,%esi
mov    $0x0,%al
call   1040 <signal@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119a <callsys+0x2a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1080 <execv@plt>
mov    -0x10(%rbp),%rsi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    120d <callsys+0x9d>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1290 <callsys+0x120>
jmp    1212 <callsys+0xa2>
jmp    1217 <callsys+0xa7>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1070 <wait@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
je     123a <callsys+0xca>
jmp    1217 <callsys+0xa7>
mov    -0x20(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1282 <callsys+0x112>
cmpl   $0x2,-0x1c(%rbp)
je     127b <callsys+0x10b>
mov    -0x10(%rbp),%rsi
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <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   10a0 <fork@plt>
cmp    $0xffffffff,%eax
je     11fe <callsys+0x7e>
mov    %eax,%ebp
test   %eax,%eax
je     1218 <callsys+0x98>
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <wait@plt>
cmp    %eax,%ebp
jne    11b0 <callsys+0x30>
mov    0xc(%rsp),%eax
test   %al,%al
je     11f9 <callsys+0x79>
cmp    $0x2,%al
je     11ee <callsys+0x6e>
movzbl %al,%ebx
lea    0xe3b(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe3d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <dexit@plt>
mov    0xc(%rsp),%eax
movzbl %ah,%eax
jmp    120f <callsys+0x8f>
lea    0xe25(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x1,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <signal@plt>
mov    $0x2,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <signal@plt>
mov    $0x3,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <signal@plt>
mov    $0x4,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <signal@plt>
mov    $0x5,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <signal@plt>
mov    $0x6,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <signal@plt>
mov    $0x7,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <signal@plt>
mov    $0x8,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <signal@plt>
mov    $0x9,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <signal@plt>
mov    $0xa,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <signal@plt>
mov    $0xb,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <signal@plt>
mov    $0xc,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <signal@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <execv@plt>
lea    0xd2c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <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 %27
11: ; preds = %2
store i32 1, i32* %8
br label %12
12: ; preds = %18, %11
%13 = load i32, i32* %8
%14 = icmp sle i32 %13, 12
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i32, i32* %8
%17 = call i32 (i32, i32, ...) bitcast (i32 (...)* @signal to i32 (i32, i32, ...)*)(i32 %16, i32 0)
br label %18
18: ; preds = %15
%19 = load i32, i32* %8
%20 = add nsw i32 %19, 1
store i32 %20, i32* %8
br label %12
21: ; preds = %12
%22 = load i8*, i8** %4
%23 = load i8**, i8*** %5
%24 = call i32 (i8*, i8**, ...) bitcast (i32 (...)* @execv to i32 (i8*, i8**, ...)*)(i8* %22, i8** %23)
%25 = load i8*, i8** %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %25)
unreachable
27: ; preds = %2
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = 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 %57
32: ; preds = %27
br label %33
33: ; preds = %32
br label %34
34: ; preds = %38, %33
%35 = load i32, i32* %6
%36 = call i32 (i32*, ...) bitcast (i32 (...)* @wait to i32 (i32*, ...)*)(i32* %7)
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %39
38: ; preds = %34
br label %34
39: ; preds = %34
%40 = load i32, i32* %7
%41 = and i32 %40, 255
store i32 %41, i32* %6
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %53
43: ; preds = %39
%44 = load i32, i32* %6
%45 = icmp ne i32 %44, 2
br i1 %45, label %46, label %51
46: ; preds = %43
%47 = load i8*, i8** %4
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = load i32, i32* %6
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %46, %43
%52 = call i32 (...) @dexit()
br label %53
53: ; preds = %51, %39
%54 = load i32, i32* %7
%55 = ashr i32 %54, 8
%56 = and i32 %55, 255
store i32 %56, i32* %3
br label %57
57: ; preds = %53, %30
%58 = load i32, i32* %3
ret i32 %58
}

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 %23 [
i32 0, label %6
i32 -1, label %21
]
6: ; preds = %2
%7 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @signal to i32 (i32, i32, ...)*)(i32 1, i32 0)
%8 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @signal to i32 (i32, i32, ...)*)(i32 2, i32 0)
%9 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @signal to i32 (i32, i32, ...)*)(i32 3, i32 0)
%10 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @signal to i32 (i32, i32, ...)*)(i32 4, i32 0)
%11 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @signal to i32 (i32, i32, ...)*)(i32 5, i32 0)
%12 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @signal to i32 (i32, i32, ...)*)(i32 6, i32 0)
%13 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @signal to i32 (i32, i32, ...)*)(i32 7, i32 0)
%14 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @signal to i32 (i32, i32, ...)*)(i32 8, i32 0)
%15 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @signal to i32 (i32, i32, ...)*)(i32 9, i32 0)
%16 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @signal to i32 (i32, i32, ...)*)(i32 10, i32 0)
%17 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @signal to i32 (i32, i32, ...)*)(i32 11, i32 0)
%18 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @signal to i32 (i32, i32, ...)*)(i32 12, i32 0)
%19 = tail call i32 (i8*, i8**, ...) bitcast (i32 (...)* @execv to i32 (i8*, i8**, ...)*)(i8* %0, i8** %1)
%20 = 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
21: ; preds = %2
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %40
23: ; preds = %2, %23
%24 = call i32 (i32*, ...) bitcast (i32 (...)* @wait to i32 (i32*, ...)*)(i32* %3)
%25 = icmp eq i32 %5, %24
br i1 %25, label %26, label %23
26: ; preds = %23
%27 = load i32, i32* %3
%28 = trunc i32 %27 to i8
switch i8 %28, label %29 [
i8 0, label %36
i8 2, label %33
]
29: ; preds = %26
%30 = and i32 %27, 255
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %30)
br label %33
33: ; preds = %26, %29
%34 = call i32 (...) @dexit()
%35 = load i32, i32* %3
br label %36
36: ; preds = %26, %33
%37 = phi i32 [ %27, %26 ], [ %35, %33 ]
%38 = lshr i32 %37, 8
%39 = and i32 %38, 255
br label %40
40: ; preds = %36, %21
%41 = phi i32 [ 1, %21 ], [ %39, %36 ]
ret i32 %41
}