#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, char const *);
int strlen(char const *);
void generate_trap_proto(FILE *out, int nr, const char *call) {
  int len = strlen(call);
  int i;
  fprintf(out, "long __trap_%i_w%s(short", nr, call);
  i = 0;
  while (i < len) {
    if (call[i] == 'w')
      fprintf(out, ", short");
    else if (call[i] == 'l')
      fprintf(out, ", long");
    else {
      printf("wrong syscall argument: %s\n", call);
      exit(1);
    }
    i++;
  }
  fprintf(out, ");\n");
}


x86 assembly (clang, -O0):
<generate_trap_proto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0xe8f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1210 <generate_trap_proto+0xd0>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x77,%eax
jne    11b7 <generate_trap_proto+0x77>
mov    -0x8(%rbp),%rdi
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1202 <generate_trap_proto+0xc2>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x6c,%eax
jne    11e3 <generate_trap_proto+0xa3>
mov    -0x8(%rbp),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11fd <generate_trap_proto+0xbd>
mov    -0x18(%rbp),%rsi
lea    0xe3a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1202 <generate_trap_proto+0xc2>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    117f <generate_trap_proto+0x3f>
mov    -0x8(%rbp),%rdi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_trap_proto>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %esi,%r15d
mov    %rdi,%r14
mov    %rdx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
lea    0xe8b(%rip),%rsi
mov    %r14,%rdi
mov    %r15d,%edx
mov    %r13,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %ebp,%ebp
jle    11db <generate_trap_proto+0x8b>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xe8d(%rip),%r15
lea    0xe7e(%rip),%r12
jmp    11be <generate_trap_proto+0x6e>
nopl   (%rax)
mov    $0x6,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %r14,%rcx
call   1070 <fwrite@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11db <generate_trap_proto+0x8b>
movzbl 0x0(%r13,%rbx,1),%eax
cmp    $0x6c,%al
je     11a0 <generate_trap_proto+0x50>
cmp    $0x77,%al
jne    1202 <generate_trap_proto+0xb2>
mov    $0x7,%esi
mov    $0x1,%edx
mov    %r12,%rdi
jmp    11ad <generate_trap_proto+0x5d>
lea    0xe62(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fwrite@plt>
lea    0xe1f(%rip),%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"long __trap_%i_w%s(short\00"
@.str.1 = [8 x i8] c", short\00"
@.str.2 = [7 x i8] c", long\00"
@.str.3 = [28 x i8] c"wrong syscall argument: %s\0A\00"
@.str.4 = [4 x i8] c");\0A\00"
define void @generate_trap_proto(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %7
%11 = load i32*, i32** %4
%12 = load i32, i32* %5
%13 = load i8*, i8** %6
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %13)
store i32 0, i32* %8
br label %15
15: ; preds = %46, %3
%16 = load i32, i32* %8
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %49
19: ; preds = %15
%20 = load i8*, i8** %6
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 119
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = load i32*, i32** %4
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %46
30: ; preds = %19
%31 = load i8*, i8** %6
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 108
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = load i32*, i32** %4
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %45
41: ; preds = %30
%42 = load i8*, i8** %6
%43 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %38
br label %46
46: ; preds = %45, %27
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %15
49: ; preds = %15
%50 = load i32*, i32** %4
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"long __trap_%i_w%s(short\00"
@.str.1 = [8 x i8] c", short\00"
@.str.2 = [7 x i8] c", long\00"
@.str.3 = [28 x i8] c"wrong syscall argument: %s\0A\00"
@.str.4 = [4 x i8] c");\0A\00"
define void @generate_trap_proto(i32* nocapture %0, i32 %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %2)
%6 = icmp sgt i32 %4, 0
br i1 %6, label %7, label %23
7: ; preds = %3
%8 = zext i32 %4 to i64
br label %9
9: ; preds = %7, %20
%10 = phi i64 [ 0, %7 ], [ %21, %20 ]
%11 = getelementptr inbounds i8, i8* %2, i64 %10
%12 = load i8, i8* %11
switch i8 %12, label %17 [
i8 119, label %13
i8 108, label %15
]
13: ; preds = %9
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 7, i64 1, i32* %0)
br label %20
15: ; preds = %9
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 6, i64 1, i32* %0)
br label %20
17: ; preds = %9
%18 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %15, %13
%21 = add nuw nsw i64 %10, 1
%22 = icmp eq i64 %21, %8
br i1 %22, label %23, label %9
23: ; preds = %20, %3
%24 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 3, i64 1, i32* %0)
ret void
}