#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ strlen(char *);
int syscall(int, int, char *, int /*<<< orphan*/);
void main() {
  int pid;
  char tag[32] = "";
  printf("pid = ");
  scanf("%d", &pid);
  int length = syscall(341, pid, tag, strlen(tag));
  if (length < 0)
    printf("error\n");
  else
    printf("success, %s\n", tag);
  return;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8a(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x44(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x44(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    %eax,%ecx
mov    $0x155,%edi
call   1060 <syscall@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11d0 <main+0x80>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e2 <main+0x92>
lea    -0x30(%rbp),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0xe95(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe8e(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    $0x155,%edi
mov    %ebx,%esi
mov    %r14,%rdx
mov    %eax,%ecx
call   1060 <syscall@plt>
test   %eax,%eax
js     11be <main+0x6e>
lea    0xe5a(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11ca <main+0x7a>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"pid = \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [7 x i8] c"error\0A\00"
@.str.3 = [13 x i8] c"success, %s\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca i32
%4 = bitcast [32 x i8]* %2 to i8*
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
%11 = call i32 @syscall(i32 341, i32 %7, i8* %8, i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %19
16: ; preds = %0
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %14
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"pid = \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [13 x i8] c"success, %s\0A\00"
@str = [6 x i8] c"error\00"
define void @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = call i32 @strlen(i8* %4)
%9 = call i32 @syscall(i32 341, i32 %7, i8* %4, i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %15
15: ; preds = %13, %11
ret void
}