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

/* Variables and functions */
int /*<<< orphan*/ BUFSIZ;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getpid();
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, int, int, char *);
int read(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int main(int argc, char *argv[]) {
  int data_processed;
  char buffer[BUFSIZ + 1];
  int file_descriptor;
  memset(buffer, '\0', sizeof(buffer));
  sscanf(argv[1], "%d", &file_descriptor);
  data_processed = read(file_descriptor, buffer, BUFSIZ);
  printf("%d - read %d bytes: %s\n", getpid(), data_processed, buffer);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe43(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1070 <sscanf@plt>
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edi
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x38(%rbp),%rcx
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e6c(%rip),%r15
mov    (%r15),%edx
add    $0x1,%edx
mov    %rsp,%rbx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x8(%r14),%rdi
lea    0xe60(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1070 <sscanf@plt>
mov    -0x1c(%rbp),%edi
mov    (%r15),%edx
mov    %rbx,%rsi
call   1060 <read@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe3b(%rip),%rdi
mov    %eax,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
call   1040 <printf@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [24 x i8] c"%d - read %d bytes: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @BUFSIZ
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i8, i64 %12
store i64 %12, i64* %8
%15 = trunc i64 %12 to i32
%16 = call i32 @memset(i8* %14, i8 signext 0, i32 %15)
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
%21 = load i32, i32* %9
%22 = load i32, i32* @BUFSIZ
%23 = call i32 @read(i32 %21, i8* %14, i32 %22)
store i32 %23, i32* %6
%24 = call i32 (...) @getpid()
%25 = load i32, i32* %6
%26 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25, i8* %14)
%27 = load i32, i32* @EXIT_SUCCESS
%28 = call i32 @exit(i32 %27)
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [24 x i8] c"%d - read %d bytes: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = load i32, i32* @BUFSIZ
%5 = add nsw i32 %4, 1
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = bitcast i32* %3 to i8*
%9 = call i32 @memset(i8* %7, i8 signext 0, i32 %5)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%13 = load i32, i32* %3
%14 = load i32, i32* @BUFSIZ
%15 = call i32 @read(i32 %13, i8* %7, i32 %14)
%16 = call i32 (...) @getpid()
%17 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %15, i8* %7)
%18 = load i32, i32* @EXIT_SUCCESS
%19 = call i32 @exit(i32 %18)
unreachable
}