void sendmesg(char *url) {
  char *port;
  char *path_info;
  char path[500];
  if (strchr(url, ':'))
    printf("Location: %s%c%c", url, 10, 10);
  else {
    printf("Location: http://%s", getenv("SERVER_NAME"));
    if ((port = getenv("SERVER_PORT")) && strcmp(port, "80"))
      printf(":%s", port);
    if (url[0] == '/') {
      printf("%s%c%c", url, 10, 10);
    } else {
      if ((path_info = getenv("PATH_INFO"))) {
        char *last = strrchr(path_info, '/');
        int x = 0;
        while (((path_info + x) <= last) && (x < 500)) {
          path[x] = *(path_info + x);
          x++;
        }
        path[x] = '\0';
      } else {
        strcpy(path, "/");
      }
      printf("%s%s%c%c", path, url, 10, 10);
    }
  }
  printf("This document has moved <A HREF=\"%s\">here</A>%c", url, 10);
  exit(1);
}


x86 assembly (clang, -O0):
<sendmesg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     11b5 <sendmesg+0x45>
mov    -0x8(%rbp),%rsi
lea    0xe5e(%rip),%rdi
mov    $0xa,%ecx
mov    %ecx,%edx
mov    $0x0,%al
call   1060 <printf@plt>
jmp    134e <sendmesg+0x1de>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <getenv@plt>
mov    %eax,%esi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <getenv@plt>
cltq
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     121c <sendmesg+0xac>
mov    -0x10(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
je     121c <sendmesg+0xac>
mov    -0x10(%rbp),%rsi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    124a <sendmesg+0xda>
mov    -0x8(%rbp),%rsi
lea    0xdd3(%rip),%rdi
mov    $0xa,%ecx
mov    %ecx,%edx
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1349 <sendmesg+0x1d9>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <getenv@plt>
cltq
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1314 <sendmesg+0x1a4>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x218(%rbp)
movl   $0x0,-0x21c(%rbp)
mov    -0x18(%rbp),%rcx
movslq -0x21c(%rbp),%rax
add    %rax,%rcx
xor    %eax,%eax
cmp    -0x218(%rbp),%rcx
mov    %al,-0x21d(%rbp)
ja     12bd <sendmesg+0x14d>
cmpl   $0x1f4,-0x21c(%rbp)
setl   %al
mov    %al,-0x21d(%rbp)
mov    -0x21d(%rbp),%al
test   $0x1,%al
jne    12d0 <sendmesg+0x160>
jmp    1300 <sendmesg+0x190>
mov    -0x18(%rbp),%rax
movslq -0x21c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x21c(%rbp),%rax
mov    %cl,-0x210(%rbp,%rax,1)
mov    -0x21c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x21c(%rbp)
jmp    1287 <sendmesg+0x117>
movslq -0x21c(%rbp),%rax
movb   $0x0,-0x210(%rbp,%rax,1)
jmp    1327 <sendmesg+0x1b7>
lea    -0x210(%rbp),%rdi
lea    0xd2c(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x210(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xd17(%rip),%rdi
mov    $0xa,%r8d
mov    %r8d,%ecx
mov    $0x0,%al
call   1060 <printf@plt>
jmp    134e <sendmesg+0x1de>
mov    -0x8(%rbp),%rsi
lea    0xd00(%rip),%rdi
mov    $0xa,%edx
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<sendmesg>:
push   %r14
push   %rbx
sub    $0x1f8,%rsp
mov    %rdi,%r14
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11e2 <sendmesg+0x82>
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1030 <getenv@plt>
lea    0xe80(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe90(%rip),%rdi
xor    %eax,%eax
call   1030 <getenv@plt>
test   %eax,%eax
je     11d3 <sendmesg+0x73>
movslq %eax,%rbx
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11d3 <sendmesg+0x73>
lea    0xe77(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmpb   $0x2f,(%r14)
jne    1202 <sendmesg+0xa2>
lea    0xe2a(%rip),%rdi
jmp    11e9 <sendmesg+0x89>
lea    0xe17(%rip),%rdi
mov    %r14,%rsi
mov    $0xa,%edx
mov    $0xa,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1287 <sendmesg+0x127>
lea    0xe3b(%rip),%rdi
xor    %eax,%eax
call   1030 <getenv@plt>
test   %eax,%eax
jne    121c <sendmesg+0xbc>
movw   $0x2f,(%rsp)
jmp    1268 <sendmesg+0x108>
movslq %eax,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
cmp    %rbx,%rax
jae    1235 <sendmesg+0xd5>
xor    %ecx,%ecx
jmp    1264 <sendmesg+0x104>
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
movzbl (%rbx,%rdx,1),%ecx
mov    %cl,(%rsp,%rdx,1)
lea    0x1(%rdx),%rcx
lea    (%rbx,%rdx,1),%rsi
add    $0x1,%rsi
cmp    %rax,%rsi
ja     1264 <sendmesg+0x104>
cmp    $0x1f3,%rdx
mov    %rcx,%rdx
jb     1240 <sendmesg+0xe0>
movb   $0x0,(%rsp,%rcx,1)
lea    0xddf(%rip),%rdi
mov    %rsp,%rsi
mov    %r14,%rdx
mov    $0xa,%ecx
mov    $0xa,%r8d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdc9(%rip),%rdi
mov    %r14,%rsi
mov    $0xa,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Location: %s%c%c\00"
@.str.1 = [20 x i8] c"Location: http://%s\00"
@.str.2 = [12 x i8] c"SERVER_NAME\00"
@.str.3 = [12 x i8] c"SERVER_PORT\00"
@.str.4 = [3 x i8] c"80\00"
@.str.5 = [4 x i8] c":%s\00"
@.str.6 = [7 x i8] c"%s%c%c\00"
@.str.7 = [10 x i8] c"PATH_INFO\00"
@.str.8 = [2 x i8] c"/\00"
@.str.9 = [9 x i8] c"%s%s%c%c\00"
@.str.10 = [48 x i8] c"This document has moved <A HREF=\22%s\22>here</A>%c\00"
define void @sendmesg(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [500 x i8]
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i8* @strchr(i8* %8, i32 58)
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %12, i32 10, i32 10)
br label %80
14: ; preds = %1
%15 = call i32 (i8*, ...) bitcast (i32 (...)* @getenv to i32 (i8*, ...)*)(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i32 (i8*, ...) bitcast (i32 (...)* @getenv to i32 (i8*, ...)*)(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %3
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %28
21: ; preds = %14
%22 = load i8*, i8** %3
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i8*, i8** %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %21, %14
%29 = load i8*, i8** %2
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 47
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = load i8*, i8** %2
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %35, i32 10, i32 10)
br label %79
37: ; preds = %28
%38 = call i32 (i8*, ...) bitcast (i32 (...)* @getenv to i32 (i8*, ...)*)(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%39 = sext i32 %38 to i64
%40 = inttoptr i64 %39 to i8*
store i8* %40, i8** %4
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %72
42: ; preds = %37
%43 = load i8*, i8** %4
%44 = call i8* @strrchr(i8* %43, i32 47)
store i8* %44, i8** %6
store i32 0, i32* %7
br label %45
45: ; preds = %57, %42
%46 = load i8*, i8** %4
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8*, i8** %6
%51 = icmp ule i8* %49, %50
br i1 %51, label %52, label %55
52: ; preds = %45
%53 = load i32, i32* %7
%54 = icmp slt i32 %53, 500
br label %55
55: ; preds = %52, %45
%56 = phi i1 [ false, %45 ], [ %54, %52 ]
br i1 %56, label %57, label %68
57: ; preds = %55
%58 = load i8*, i8** %4
%59 = load i32, i32* %7
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = load i8, i8* %61
%63 = load i32, i32* %7
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 %64
store i8 %62, i8* %65
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %45
68: ; preds = %55
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 %70
store i8 0, i8* %71
br label %75
72: ; preds = %37
%73 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 0
%74 = call i8* @strcpy(i8* %73, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %75
75: ; preds = %72, %68
%76 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 0
%77 = load i8*, i8** %2
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i8* %76, i8* %77, i32 10, i32 10)
br label %79
79: ; preds = %75, %34
br label %80
80: ; preds = %79, %11
%81 = load i8*, i8** %2
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.10, i64 0, i64 0), i8* %81, i32 10)
unreachable
}

LLVM IR (-O2):
@.str = [17 x i8] c"Location: %s%c%c\00"
@.str.1 = [20 x i8] c"Location: http://%s\00"
@.str.2 = [12 x i8] c"SERVER_NAME\00"
@.str.3 = [12 x i8] c"SERVER_PORT\00"
@.str.4 = [3 x i8] c"80\00"
@.str.5 = [4 x i8] c":%s\00"
@.str.6 = [7 x i8] c"%s%c%c\00"
@.str.7 = [10 x i8] c"PATH_INFO\00"
@.str.9 = [9 x i8] c"%s%s%c%c\00"
@.str.10 = [48 x i8] c"This document has moved <A HREF=\22%s\22>here</A>%c\00"
define void @sendmesg(i8* %0) {
%2 = alloca [500 x i8]
%3 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i32 10, i32 10)
br label %50
8: ; preds = %1
%9 = tail call i32 (i8*, ...) bitcast (i32 (...)* @getenv to i32 (i8*, ...)*)(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = tail call i32 (i8*, ...) bitcast (i32 (...)* @getenv to i32 (i8*, ...)*)(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i8*
%14 = icmp eq i32 %11, 0
br i1 %14, label %20, label %15
15: ; preds = %8
%16 = tail call i32 @strcmp(i8* %13, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %13)
br label %20
20: ; preds = %18, %15, %8
%21 = load i8, i8* %0
%22 = icmp eq i8 %21, 47
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %0, i32 10, i32 10)
br label %50
25: ; preds = %20
%26 = tail call i32 (i8*, ...) bitcast (i32 (...)* @getenv to i32 (i8*, ...)*)(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%27 = sext i32 %26 to i64
%28 = inttoptr i64 %27 to i8*
%29 = icmp eq i32 %26, 0
br i1 %29, label %46, label %30
30: ; preds = %25
%31 = tail call i8* @strrchr(i8* %28, i32 47)
%32 = icmp ult i8* %31, %28
br i1 %32, label %43, label %33
33: ; preds = %30, %33
%34 = phi i64 [ %38, %33 ], [ 0, %30 ]
%35 = phi i8* [ %39, %33 ], [ %28, %30 ]
%36 = load i8, i8* %35
%37 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 %34
store i8 %36, i8* %37
%38 = add nuw nsw i64 %34, 1
%39 = getelementptr inbounds i8, i8* %28, i64 %38
%40 = icmp ule i8* %39, %31
%41 = icmp ult i64 %34, 499
%42 = and i1 %40, %41
br i1 %42, label %33, label %43
43: ; preds = %33, %30
%44 = phi i64 [ 0, %30 ], [ %38, %33 ]
%45 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 %44
store i8 0, i8* %45
br label %48
46: ; preds = %25
%47 = bitcast [500 x i8]* %2 to i16*
store i16 47, i16* %47
br label %48
48: ; preds = %46, %43
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i8* %3, i8* %0, i32 10, i32 10)
br label %50
50: ; preds = %23, %48, %6
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.10, i64 0, i64 0), i8* %0, i32 10)
unreachable
}