#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 uint32_t;
struct asmbuf {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ asmbuf_immediate(struct asmbuf *, int, int *);
int /*<<< orphan*/ asmbuf_ins(struct asmbuf *, int, int);
void asmbuf_syscall(struct asmbuf *buf, int syscall) {
  if (syscall == 0) {
    asmbuf_ins(buf, 2, 0x31C0);
  } else if (syscall == 1) {
    asmbuf_ins(buf, 3, 0x4C89E0);
  } else {
    asmbuf_ins(buf, 1, 0xB8);
    uint32_t n = syscall;
    asmbuf_immediate(buf, 4, &n);
  }
  asmbuf_ins(buf, 2, 0x0F05);
}


x86 assembly (clang, -O0):
<asmbuf_syscall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1151 <asmbuf_syscall+0x31>
mov    -0x8(%rbp),%rdi
mov    $0x2,%esi
mov    $0x31c0,%edx
call   1030 <asmbuf_ins@plt>
jmp    11a3 <asmbuf_syscall+0x83>
cmpl   $0x1,-0xc(%rbp)
jne    1173 <asmbuf_syscall+0x53>
mov    -0x8(%rbp),%rdi
mov    $0x3,%esi
mov    $0x4c89e0,%edx
call   1030 <asmbuf_ins@plt>
jmp    119e <asmbuf_syscall+0x7e>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
mov    $0xb8,%edx
call   1030 <asmbuf_ins@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x4,%esi
lea    -0x10(%rbp),%rdx
call   1040 <asmbuf_immediate@plt>
jmp    11a3 <asmbuf_syscall+0x83>
mov    -0x8(%rbp),%rdi
mov    $0x2,%esi
mov    $0xf05,%edx
call   1030 <asmbuf_ins@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asmbuf_syscall>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
cmp    $0x1,%esi
je     1145 <asmbuf_syscall+0x25>
mov    %esi,%ebp
mov    %rbx,%rdi
test   %esi,%esi
jne    1159 <asmbuf_syscall+0x39>
mov    $0x2,%esi
mov    $0x31c0,%edx
call   1030 <asmbuf_ins@plt>
jmp    117e <asmbuf_syscall+0x5e>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x4c89e0,%edx
call   1030 <asmbuf_ins@plt>
jmp    117e <asmbuf_syscall+0x5e>
mov    $0x1,%esi
mov    $0xb8,%edx
call   1030 <asmbuf_ins@plt>
mov    %ebp,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1040 <asmbuf_immediate@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0xf05,%edx
call   1030 <asmbuf_ins@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.asmbuf = type { i32 }
define void @asmbuf_syscall(%struct.asmbuf* %0, i32 %1) {
%3 = alloca %struct.asmbuf*
%4 = alloca i32
%5 = alloca i32
store %struct.asmbuf* %0, %struct.asmbuf** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load %struct.asmbuf*, %struct.asmbuf** %3
%10 = call i32 @asmbuf_ins(%struct.asmbuf* %9, i32 2, i32 12736)
br label %24
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load %struct.asmbuf*, %struct.asmbuf** %3
%16 = call i32 @asmbuf_ins(%struct.asmbuf* %15, i32 3, i32 5016032)
br label %23
17: ; preds = %11
%18 = load %struct.asmbuf*, %struct.asmbuf** %3
%19 = call i32 @asmbuf_ins(%struct.asmbuf* %18, i32 1, i32 184)
%20 = load i32, i32* %4
store i32 %20, i32* %5
%21 = load %struct.asmbuf*, %struct.asmbuf** %3
%22 = call i32 @asmbuf_immediate(%struct.asmbuf* %21, i32 4, i32* %5)
br label %23
23: ; preds = %17, %14
br label %24
24: ; preds = %23, %8
%25 = load %struct.asmbuf*, %struct.asmbuf** %3
%26 = call i32 @asmbuf_ins(%struct.asmbuf* %25, i32 2, i32 3845)
ret void
}

LLVM IR (-O2):
%struct.asmbuf = type { i32 }
define void @asmbuf_syscall(%struct.asmbuf* %0, i32 %1) {
%3 = alloca i32
switch i32 %1, label %8 [
i32 0, label %4
i32 1, label %6
]
4: ; preds = %2
%5 = tail call i32 @asmbuf_ins(%struct.asmbuf* %0, i32 2, i32 12736)
br label %12
6: ; preds = %2
%7 = tail call i32 @asmbuf_ins(%struct.asmbuf* %0, i32 3, i32 5016032)
br label %12
8: ; preds = %2
%9 = tail call i32 @asmbuf_ins(%struct.asmbuf* %0, i32 1, i32 184)
%10 = bitcast i32* %3 to i8*
store i32 %1, i32* %3
%11 = call i32 @asmbuf_immediate(%struct.asmbuf* %0, i32 4, i32* %3)
br label %12
12: ; preds = %6, %8, %4
%13 = call i32 @asmbuf_ins(%struct.asmbuf* %0, i32 2, i32 3845)
ret void
}