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

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ on_error(char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ sem_post(int /*<<< orphan*/ *);
int /*<<< orphan*/ sem_wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcpy(char *, char *);
void save_secret(char secret[], sem_t *sem3) {
  char buffer[(50) + 1];
  if (read(STDIN_FILENO, buffer, (50)) == -1) {
    (void)on_error("Problem while executing read(2).");
  }
  buffer[(50)] = '\0';
  sem_wait(sem3);
  strcpy(secret, buffer);
  sem_post(sem3);
}


x86 assembly (clang, -O0):
<save_secret>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
mov    $0x32,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
jne    118c <save_secret+0x3c>
lea    0xe79(%rip),%rdi
call   1070 <on_error@plt>
movb   $0x0,-0x1e(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sem_wait@plt>
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <sem_post@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_secret>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x32,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
jne    1184 <save_secret+0x34>
lea    0xe81(%rip),%rdi
call   1070 <on_error@plt>
movb   $0x0,0x32(%rsp)
mov    %rbx,%rdi
call   1040 <sem_wait@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <sem_post@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@.str = [33 x i8] c"Problem while executing read(2).\00"
define void @save_secret(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [51 x i8]
store i8* %0, i8** %3
store i32* %1, i32** %4
%6 = load i32, i32* @STDIN_FILENO
%7 = getelementptr inbounds [51 x i8], [51 x i8]* %5, i64 0, i64 0
%8 = call i32 @read(i32 %6, i8* %7, i32 50)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @on_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = getelementptr inbounds [51 x i8], [51 x i8]* %5, i64 0, i64 50
store i8 0, i8* %13
%14 = load i32*, i32** %4
%15 = call i32 @sem_wait(i32* %14)
%16 = load i8*, i8** %3
%17 = getelementptr inbounds [51 x i8], [51 x i8]* %5, i64 0, i64 0
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i32*, i32** %4
%20 = call i32 @sem_post(i32* %19)
ret void
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str = [33 x i8] c"Problem while executing read(2).\00"
define void @save_secret(i8* %0, i32* %1) {
%3 = alloca [51 x i8]
%4 = getelementptr inbounds [51 x i8], [51 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @STDIN_FILENO
%6 = call i32 @read(i32 %5, i8* %4, i32 50)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @on_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = getelementptr inbounds [51 x i8], [51 x i8]* %3, i64 0, i64 50
store i8 0, i8* %11
%12 = tail call i32 @sem_wait(i32* %1)
%13 = call i32 @strcpy(i8* %0, i8* %4)
%14 = call i32 @sem_post(i32* %1)
ret void
}