#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);
int sem_create(int);
int sem_getval(int);
int /*<<< orphan*/ sem_p(int);
int /*<<< orphan*/ sem_setval(int, int);
int /*<<< orphan*/ sem_v(int);
int main(void) {
  int semid;
  semid = sem_create(1234);
  sem_setval(semid, 5);
  printf("val=%d\n", sem_getval(semid));
  sem_p(semid);
  printf("val=%d\n", sem_getval(semid));
  sem_p(semid);
  printf("val=%d\n", sem_getval(semid));
  sem_v(semid);
  printf("val=%d\n", sem_getval(semid));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4d2,%edi
call   1050 <sem_create@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1060 <sem_setval@plt>
mov    -0x8(%rbp),%edi
call   1070 <sem_getval@plt>
mov    %eax,%esi
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1080 <sem_p@plt>
mov    -0x8(%rbp),%edi
call   1070 <sem_getval@plt>
mov    %eax,%esi
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1080 <sem_p@plt>
mov    -0x8(%rbp),%edi
call   1070 <sem_getval@plt>
mov    %eax,%esi
lea    0xe2a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <sem_v@plt>
mov    -0x8(%rbp),%edi
call   1070 <sem_getval@plt>
mov    %eax,%esi
lea    0xe0c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x4d2,%edi
call   1050 <sem_create@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x5,%esi
call   1060 <sem_setval@plt>
mov    %ebx,%edi
call   1070 <sem_getval@plt>
lea    0xe76(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1080 <sem_p@plt>
mov    %ebx,%edi
call   1070 <sem_getval@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1080 <sem_p@plt>
mov    %ebx,%edi
call   1070 <sem_getval@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1040 <sem_v@plt>
mov    %ebx,%edi
call   1070 <sem_getval@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"val=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @sem_create(i32 1234)
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @sem_setval(i32 %4, i32 5)
%6 = load i32, i32* %2
%7 = call i32 @sem_getval(i32 %6)
%8 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %2
%10 = call i32 @sem_p(i32 %9)
%11 = load i32, i32* %2
%12 = call i32 @sem_getval(i32 %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %2
%15 = call i32 @sem_p(i32 %14)
%16 = load i32, i32* %2
%17 = call i32 @sem_getval(i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %2
%20 = call i32 @sem_v(i32 %19)
%21 = load i32, i32* %2
%22 = call i32 @sem_getval(i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"val=%d\0A\00"
define i32 @main() {
%1 = tail call i32 @sem_create(i32 1234)
%2 = tail call i32 @sem_setval(i32 %1, i32 5)
%3 = tail call i32 @sem_getval(i32 %1)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @sem_p(i32 %1)
%6 = tail call i32 @sem_getval(i32 %1)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 @sem_p(i32 %1)
%9 = tail call i32 @sem_getval(i32 %1)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = tail call i32 @sem_v(i32 %1)
%12 = tail call i32 @sem_getval(i32 %1)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %12)
ret i32 0
}