#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 /*<<< orphan*/ smp_print_error();
int smp_sem_create(int, int);
int /*<<< orphan*/ smp_sem_remove(int);
int /*<<< orphan*/ smp_test_sem_getset(int);
int smp_test_semget() {
  int semid = 12345677;
  semid = smp_sem_create(semid, 3);
  if (semid == (-1)) {
    smp_print_error();
    return (-1);
  }
  printf("semid is %d\n", semid);
  smp_test_sem_getset(semid);
  smp_sem_remove(semid);
  return (0);
}


x86 assembly (clang, -O0):
<smp_test_semget>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xbc614d,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x3,%esi
call   1070 <smp_sem_create@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    118c <smp_test_semget+0x3c>
mov    $0x0,%al
call   1040 <smp_print_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <smp_test_semget+0x62>
mov    -0x8(%rbp),%esi
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <smp_test_sem_getset@plt>
mov    -0x8(%rbp),%edi
call   1030 <smp_sem_remove@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smp_test_semget>:
push   %rbx
mov    $0xbc614d,%edi
mov    $0x3,%esi
call   1070 <smp_sem_create@plt>
cmp    $0xffffffff,%eax
je     1187 <smp_test_semget+0x37>
mov    %eax,%ebx
lea    0xe92(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <smp_test_sem_getset@plt>
mov    %ebx,%edi
call   1030 <smp_sem_remove@plt>
xor    %eax,%eax
pop    %rbx
ret
xor    %eax,%eax
call   1040 <smp_print_error@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"semid is %d\0A\00"
define i32 @smp_test_semget() {
%1 = alloca i32
%2 = alloca i32
store i32 12345677, i32* %2
%3 = load i32, i32* %2
%4 = call i32 @smp_sem_create(i32 %3, i32 3)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (...) @smp_print_error()
store i32 -1, i32* %1
br label %16
9: ; preds = %0
%10 = load i32, i32* %2
%11 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %2
%13 = call i32 @smp_test_sem_getset(i32 %12)
%14 = load i32, i32* %2
%15 = call i32 @smp_sem_remove(i32 %14)
store i32 0, i32* %1
br label %16
16: ; preds = %9, %7
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [13 x i8] c"semid is %d\0A\00"
define i32 @smp_test_semget() {
%1 = tail call i32 @smp_sem_create(i32 12345677, i32 3)
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 (...) @smp_print_error()
br label %9
5: ; preds = %0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%7 = tail call i32 @smp_test_sem_getset(i32 %1)
%8 = tail call i32 @smp_sem_remove(i32 %1)
br label %9
9: ; preds = %5, %3
%10 = phi i32 [ -1, %3 ], [ 0, %5 ]
ret i32 %10
}