#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 getpid();
int /*<<< orphan*/ printf(char *, int, int);
scalar_t__ shmat(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ shmdt(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
void print_hundred(int segment_id) {
  char *shared_memory;
  int number;
  shared_memory = (char *)shmat(segment_id, 0, 0);
  sscanf(shared_memory, "%d", &number);
  number++;
  sprintf(shared_memory, "%d", number);
  sscanf(shared_memory, "%d", &number);
  number--;
  sprintf(shared_memory, "%d", number);
  sscanf(shared_memory, "%d", &number);
  printf("Number: %d - PID: %d\n", number, getpid());
  shmdt(shared_memory);
}


x86 assembly (clang, -O0):
<print_hundred>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1070 <shmat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7a(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe5a(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe4a(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe2a(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe1a(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x18(%rbp),%esi
mov    %eax,%edx
lea    0xdfb(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <shmdt@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hundred>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %esi,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
mov    %rax,%rbx
lea    0xe86(%rip),%r14
lea    0x4(%rsp),%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <sscanf@plt>
mov    0x4(%rsp),%edx
add    $0x1,%edx
mov    %edx,0x4(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <sscanf@plt>
mov    0x4(%rsp),%edx
add    $0xffffffff,%edx
mov    %edx,0x4(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <sscanf@plt>
mov    0x4(%rsp),%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe1c(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <shmdt@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [22 x i8] c"Number: %d - PID: %d\0A\00"
define void @print_hundred(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i64 @shmat(i32 %5, i32 0, i32 0)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%10 = load i32, i32* %4
%11 = add nsw i32 %10, 1
store i32 %11, i32* %4
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i8*, i8** %3
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%17 = load i32, i32* %4
%18 = add nsw i32 %17, -1
store i32 %18, i32* %4
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i8*, i8** %3
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%24 = load i32, i32* %4
%25 = call i32 (...) @getpid()
%26 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25)
%27 = load i8*, i8** %3
%28 = call i32 @shmdt(i8* %27)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [22 x i8] c"Number: %d - PID: %d\0A\00"
define void @print_hundred(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i64 @shmat(i32 %0, i32 0, i32 0)
%5 = inttoptr i64 %4 to i8*
%6 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = add nsw i32 %7, 1
store i32 %8, i32* %2
%9 = call i32 @sprintf(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = add nsw i32 %11, -1
store i32 %12, i32* %2
%13 = call i32 @sprintf(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%15 = load i32, i32* %2
%16 = call i32 (...) @getpid()
%17 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16)
%18 = call i32 @shmdt(i8* %5)
ret void
}